How to avoid nested transactions not supported error?

前端 未结 5 1790
借酒劲吻你
借酒劲吻你 2020-12-08 05:15

I need to make sure many concurrent users be able to access the database. Although after each commit I close the session but sometimes my code runs into following error, but

5条回答
  •  半阙折子戏
    2020-12-08 05:47

    Use session.beginTransaction() instead of session.getTransaction().begin() in your code. You need to begin a new unit of work, so beginTransaction will begin a new transaction. So your code will look like:

    session = HibernateUtil.getSession();
    Transaction transaction = session.beginTransaction();
           ...   to do ....
    transaction.commit();
    

    Click Here to get more information about beginTransaction(); method.

    I think that will resolve your issue. Please let me know if issue persists.

提交回复
热议问题