简体   繁体   English

无法使用Hibernate创建会话

[英]Unable to create session using Hibernate

To test whether Hibernate session factory is working fine or not, I tried using the following code. 为了测试Hibernate会话工厂是否工作正常,我尝试使用以下代码。

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. 修复该映射后,它可以完全解决。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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