search

Home  >  Q&A  >  body text

How to solve Hibernate's multi-threading problem?

I have a page that implements a function. Triggering this function will execute two java functions at the same time, thereby triggering two Hibernate operations. After executing this function, the system will issue this Exception from time to time:

org.hibernate.TransactionException: Transaction not successfully started

I personally think it is because the session was closed by the previous Hibernate operation, resulting in the transaction of the latter operation being unable to be executed.
After Baidu, I tried this method, but it didn’t seem to work:

        <property name="hibernateProperties">  
            <props>
                <prop key="hibernate.autoReconnect">true</prop>
            </props>
        </property>

So, let me ask an expert to give me some advice.

淡淡烟草味淡淡烟草味2777 days ago593

reply all(1)I'll reply

  • 黄舟

    黄舟2017-05-17 10:09:17

    It depends on what your code is.
    Is your trigger multi-threaded or just executing two different methods in the same thread?
    For example, service.method1, service.method2, the aspect of the transaction is in the service layer , then these two method transactions are independent,

    reply
    0
  • Cancelreply