I'm using Hibernate 5.1.0.Final and PostgreSQL 9.5; All jars are added to lib properly; Can someone please point out what is the actual problem here ?
Asked
Active
Viewed 894 times
0
-
FYI, The line throwing exception in TestHibernate is marked in blue. – izengod Feb 14 '16 at 12:56
-
Possible duplicate of [Error in configuring hibernate 5.0.1 and MySQL](http://stackoverflow.com/questions/32499073/error-in-configuring-hibernate-5-0-1-and-mysql) – user2004685 Feb 14 '16 at 13:01
-
didn't work in my case though :( – izengod Feb 14 '16 at 13:13
3 Answers
0
Since hibernate 4.x buildsessionfactory() has been deprecated. You need to fetch a session like below :
Configuration config = new Configuration()
.configure();
ServiceRegistry serviceRegistery = new StandardServiceRegistryBuilder().applySettings(config.getProperties()).build();
SessionFactory sessionFactory = config.buildSessionFactory(serviceRegistery);
Session session = sessionFactory.openSession();

Ankit Tripathi
- 405
- 4
- 13
-
Same error in: Configuration config = new Configuration().configure(); – izengod Feb 14 '16 at 13:10
-
`buildSessionFactory()` is not deprecated in Hibernate 5. And, sorry, your configuration approach will not work for Hibernate 5. Please, [check it](http://stackoverflow.com/a/32711654/3405171) – v.ladynev Feb 17 '16 at 06:01
0
A problem, obviously, with hibernate.cfg.xml
parsing. Try to use this template
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
...
</session-factory>
</hibernate-configuration>
And you need to close a session.

v.ladynev
- 19,275
- 8
- 46
- 67
0
Ok so here is the solution. mapping class will always be the class where you are creating all the attributes for the objects(the class containing details and getters,setters), not the one where you're using hibernate API to save objects to database.
<mapping class="org.hibernate.sample.UserDetails"/>

izengod
- 1,116
- 5
- 17
- 41