0

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 ?

Exception details

TestHibernate class

hibernate config file

izengod
  • 1,116
  • 5
  • 17
  • 41

3 Answers3

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