简体   繁体   中英

Unable to create session using Hibernate

To test whether Hibernate session factory is working fine or not, I tried using the following code.

public class HibernateUtilities {

    private static SessionFactory sessionFactory;
    ......
    }

    public static SessionFactory getSessionFactory() {
        return sessionFactory;
    }

    public static void main(String[] args) {
        Session session = ....
        session.beginTransaction();

        session.getTransaction().commit();
        session.close();

    }

}

But I am getting the following error:

Exception in thread "main" Problem creating session factory
java.lang.NullPointerException
    at com.test.HibernateUtilities.main(HibernateUtilities.java:50)

My hibernate configuration code is like the following:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration.....>
<hibernate-configuration>
    <session-factory>
        ........
    </session-factory>
</hibernate-configuration>

What is the reason that I am getting this error.

I fixed the problem. The problem was not to create the session factory. The problem was the mapping of Entity with one to one relationship with other entity. After fixing that mapping, it solves totally.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM