4.1.9休眠(最新最终版本)报告`嵌套事务不supported` [英] Hibernate 4.1.9 (latest final build) reporting `nested transactions not supported`

查看:146
本文介绍了4.1.9休眠(最新最终版本)报告`嵌套事务不supported`的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到一个

org.hibernate.TransactionException: nested transactions not supported
at    org.hibernate.engine.transaction.spi.AbstractTransactionImpl.begin(AbstractTransactionImpl.java:152)
at org.hibernate.internal.SessionImpl.beginTransaction(SessionImpl.java:1395)
at com.mcruiseon.server.hibernate.ReadOnlyOperations.flush(ReadOnlyOperations.java:118)

code抛出该异常。我打电话从运行无限线程冲洗,直到有数据刷新。

Code that throws that exception. I am calling flush from a thread that runs infinite until there is data to flush.

public void flush(Object dataStore) throws DidNotSaveRequestSomeRandomError {
    Transaction txD;
    Session session;
    session = currentSession();
    // Below Line 118 
    txD = session.beginTransaction();
    txD.begin() ;
    session.saveOrUpdate(dataStore);
    try {
        txD.commit();
        while(!txD.wasCommitted()) ;
    } catch (ConstraintViolationException e) {
        txD.rollback() ;
        throw new DidNotSaveRequestSomeRandomError(dataStore, feedbackManager);
    } catch (TransactionException e) {
        txD.rollback() ;
    }  finally {
        // session.flush();
        txD = null;
        session.close();
    }
    // mySession.clear();
}

编辑:
作为数据存储列表中包含的数据我打电话一个独立的线程齐平。从我看到它的同步操作调用刷新,因此,最好冲洗不应该返回,直到交易完成。我想这种方式是我想期望最少​​。自从一个独立的线程做自己的工作,我所关心的是冲洗是一个同步操作。现在我的问题是,一个txD.commit异步操作?是否返回之前交易有机会来完成。如果是的话,有没有办法让承诺等待,直到事务完成?

Edit : I am calling flush in a independent thread as datastore list contains data. From what I see its a sync operation call to flush, so ideally flush should not return until transaction is complete. I would like it that way is the least I want to expect. Since its a independent thread doing its job, all I care about it flush being a sync operation. Now my question is, is txD.commit a async operation ? Does it return before that transaction has a chance to finish. If yes, is there a way to get commit to "Wait" until the transaction completes ?

        public void run() {
        Object dataStore = null;
        while (true) {
            try {
                synchronized (flushQ) {
                    if (flushQ.isEmpty())
                        flushQ.wait();
                    if (flushQ.isEmpty()) {
                        continue;
                    }
                    dataStore = flushQ.removeFirst();
                    if (dataStore == null) {
                        continue;
                    }
                }
                try {
                    flush(dataStore);
                } catch (DidNotSaveRequestSomeRandomError e) {
                    e.printStackTrace();
                    log.fatal(e);
                }
            } catch (HibernateException e) {
                e.printStackTrace();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

编辑2:(!txD.wasCommitted())新增,而(在code以上),我仍然得到吓坏嵌套事务不支持。逸岸由于这种异常的记录不会被写入表太多。有没有事做表的类型?我有INNODB为我所有的表?

Edit 2 : Added while(!txD.wasCommitted()) ; (in code above), still I get that freaking nested transactions not supported. Infact due to this exception a record is not being written to by table too. Is there something to do with the type of table ? I have INNODB for all my tables?

推荐答案

您可能已经调用此方法之前就开始了交易。

You probably already began a transaction before calling this method.

无论这应该是封闭的交易的一部分,你应该因此不启动另一个;或者它不应该是封闭的交易的一部分,因此,你应该打开一个新的会话和一个新的事务,而不是使用当前会话。

Either this should be part of the enclosing transaction, and you should thus not start another one; or it shouldn't be part of the enclosing transaction, and you should thus open a new session and a new transaction rather than using the current session.

这篇关于4.1.9休眠(最新最终版本)报告`嵌套事务不supported`的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆