When I created a hibernate Configuration file, eclipse is not able to display the source code as there is no source button at the bottom of the page. I can able to navigate between Session Factory and Security whereas Source button is missing. How can fix this issue? I have attached the picture below for reference.
Hibernate Configuration XML File
make your own one and add the below:
fileName is: hibernate.cfg.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/Book</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password"></property>
<property name="hibernate.connection.pool_size">1</property>
<property name="hibernate.current_session_context_class">thread</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<mapping resource="book.hbm.xml" />
</session-factory>
</hibernate-configuration>
And if you want to read more about it go here
Related
I'm starting learing how to use IntelliJ, and I'm trying to link my persistence to my datasource.
I've read here on SO how to do that, and now I've binded my persistence to my datasource successfully: I can run queries on database, and i can browse my persistence.
This is the db (MSSQL):
This is the persistence:
And this is the assignment:
The problem is that I'm still getting error on my class, looks like is not able to link to the datasource, and is giving me the error "Cannot resolve column" (not only on ID column, but on all columns):
The application is running fine, so the problem is only related to some wrong intellij configuration, but I can't find where the problem is.
This is my hibernate.cfg.xml (there are more tables, I've left only the one in the example):
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory name="Artemide">
<property name="hibernate.bytecode.use_reflection_optimizer">false</property>
<property name="hibernate.connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property>
<!-- Configurazione maven-->
<property name="hibernate.connection.password">${hibernate.password}</property>
<property name="hibernate.connection.username">${hibernate.username}</property>
<property name="hibernate.connection.url">${hibernate.connection.url}</property>
<property name="hibernate.default_catalog">${hibernate.default_catalog}</property>
<property name="hibernate.dialect">org.hibernate.dialect.SQLServer2008Dialect</property>
<property name="hibernate.search.autoregister_listeners">false</property>
<property name="hibernate.show_sql">false</property>
<property name="hibernate.format_sql">true</property>
<mapping class="xx.xx.xx.database.pojo.Categoria"/>
</session-factory>
</hibernate-configuration>
Thanks!
I'm making a new project with Hibernate.
I have some problems configure hibernate correctly in my Eclipse environment.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory name="">
<property name="hibernate.connection.driver_class">com.microsoft.jdbc.sqlserver.SQLServerDriver</property>
<property name="hibernate.connection.password">XXXXX</property>
<property name="hibernate.connection.url">jdbc:sqlserver://localhost/Framework</property>
<property name="hibernate.connection.username">sa</property>
<property name="hibernate.default_schema">Framework</property>
<property name="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</property>
<property name="hibernate.connection.pool_size">10</property>
<property name="show_sql">true</property>
</session-factory>
</hibernate-configuration>
My Eclipse environment only sees the master database instead of my Framework database. Can someone help me with this?
The database was not correctly configured. The user didn't have the correct permissions. After fixing this it works.
Here is my code in file named hibernate.cfg.xml
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<property name="connection.url">jdbc:mysql://localhost:3306/HeartJar</property>
<property name="connection.username">root</property>
<property name="connection.password">root</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="show_sql">true</property>
<mapping resource="com/heartjar/bean/User.hbm.xml" />
</session-factory>
</hibernate-configuration>
There was a waining saying Stream not availableat line 2
Although warnings don't have bad influences to my project.But Understanding how to solve the problem is useful for me,a beginner in JavaWeb.Thank you for your answer
I am a beginner and trying to run first simple code.
Please help me resolve the following issue.
Error on line 11 of document : The element type "session-factory" must be terminated by the matching end-tag "</session-factory>".
Nested exception: The element type "session-factory" must be terminated by the matching end-tag "</session-factory>".
at org.dom4j.io.SAXReader.read(SAXReader.java:482)
config file
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="connection.driver_class">org.postgresql.Driver</property>
<property name="connection.url">jdbc:postgresql://localhost:5432/hibernatedb</property>
<property name="connection.username">postgres</property>
<property name="connection.password"/>shaher</property>
<property name="connection.pool_size">1</property>
<property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<property name="cache.provider_class">org.hibernate.cache.internal.NoCacheProvider</property>
<property name="show_sql">true</property>
<property name="hbm2ddl.auto">create</property>
<mapping class="org.shaher.hiber.dto.UserDetails"/>
</session-factory>
</hibernate-configuration>
You need to close the tag <session-factory>
<session-factory>
...
</session-factory>
you have problem with your config file see this
<property name="connection.password"/>shaher</property>
please update it to below
<property name="connection.password">shaher</property>
After deploying a web application with maven to heroku cloud, I get log error:
app[web.1]: org.hibernate.HibernateException: hibernate.cfg.xml not found.
The web application running locally correctly, but on the cloud not.
This is my hibernate.cfg.xml:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">
com.mysql.jdbc.Driver
</property>
<property name="hibernate.connection.url">
jdbc:mysql://localhost:3306/todoitemsdb
</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">root</property>
<property name="show_sql">true</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<!-- Mapping files -->
<mapping class="il.ac.hit.model.User" resource="todoitems.xml"/>
<mapping class="il.ac.hit.model.ToDoItem" resource="users.xml"/>
</session-factory>
</hibernate-configuration>
What can I do?
Make sure that the hibernate.cfg.xml is bundled into your jar like this:
your-app.jar\hibernate.cfg.xml
That's where Hibernate tries to locate the configuration file.
I had my hibernate.cfg.xml under resources under a folder config
Changing the below line
cfg.configure("./config/hibernate.cfg.xml");
to
cfg.configure("config/hibernate.cfg.xml");
worked.