相关疑难解决方法(0)

Hibernate:没有配置CurrentSessionContext

我一直得到一个:

HibernateException:没有配置CurrentSessionContext!

在我的代码中.返回的其他搜索的唯一信息是罪魁祸首:

<property name="current_session_context_class">thread</property>
Run Code Online (Sandbox Code Playgroud)

在我的hibernate.cfg.xml中.我在我的hibernate.cfg.xml文件中有这个,我在Tomcat 6中运行它.有没有人知道其他可能的原因?

hibernate liferay

25
推荐指数
2
解决办法
4万
查看次数

为什么我得到org.hibernate.HibernateException:没有配置CurrentSessionContext

我正在编写一个简单的项目,一个用Swing编写的业务应用程序,使用Hibernate作为后端.我来自Spring,这给了我简单的方法来使用hibernate和事务.无论如何,我设法让Hibernate工作.昨天,在编写一些代码来从DB中删除bean时,我得到了这个:

org.hibernate.HibernateException: Illegal attempt to associate a collection with two open sessions
Run Code Online (Sandbox Code Playgroud)

删除代码很简单:

    Session sess = HibernateUtil.getSession();
    Transaction tx = sess.beginTransaction();
    try {
        tx.begin();
        sess.delete(ims);
    } catch (Exception e) {
        tx.rollback();
        throw e;
    }
    tx.commit();
    sess.flush();
Run Code Online (Sandbox Code Playgroud)

而我的HibernateUtil.getSession()是:

    public static Session getSession() throws HibernateException {
        Session sess = null;
        try {
            sess = sessionFactory.getCurrentSession();
        } catch (org.hibernate.HibernateException he) {
            sess = sessionFactory.openSession();
        }
        return sess;
    }
Run Code Online (Sandbox Code Playgroud)

其他细节:我从未在我的代码中关闭hibernate会话,只是关闭应用程序.这是错的吗?为什么我在删除时得到这个(只有那个bean,其他人都可以工作),而我没有进行其他操作(插入,查询,更新)?

我读了一遍,我试图getSession简单地修改我的方法sessionFactory.getCurrentSessionCall(),但我得到了:org.hibernate.HibernateException: No CurrentSessionContext configured!

Hibernat conf:

<hibernate-configuration> …
Run Code Online (Sandbox Code Playgroud)

java hibernate

21
推荐指数
2
解决办法
6万
查看次数

标签 统计

hibernate ×2

java ×1

liferay ×1