[Key error message]: TransactionException: Transactionnotsuccessfullystarted and a doCommit from this keyword, we use the Hibernate Transaction Manager (instead of the green font of the detailed log below) thrown when processing the transaction commit. [specific solution]: The following code segment reports an error Se
[Key error message]: TransactionException: Transaction not successfully started and a doCommit from this keyword, we use the Hibernate Transaction Manager (instead of Spring, the green font of the detailed log below) thrown when processing the transaction commit. [specific solution]: // the following code segment will report an error Se
[Key error information ]:TransactionException:Transaction not successfully startedAnd oneDoCommit
From this keyword, It is thrown when the Hibernate Transaction Manager (instead of Spring, the green font of the detailed log below) is used to process the transaction commit,
[Specific solution ]:
// The following code segment will report an error
Session session = getSessionFactory (). getCurrentSession (); session. beginTransaction (); // String queryString = "update .... "; // update Query query = session for specific database fields. createQuery (queryString); query.exe cuteUpdate (); session. getTransaction (). commit (); // It should have caused org. hibernate. transactionException: Transaction not successfully started
// Change to the following code snippet.
Session session = getSessionFactory (). openSession (); Transaction tran = session. beginTransaction (); // after this modification, OK String queryString = "update .... "; Query query = session. createQuery (queryString); query.exe cuteUpdate (); tran. commit (); session. close ();
[Zhuge Liang afterwards]This error is reported in an update Statement on the dao layer, but no error is prompted. Instead, it is thrown when the upper-level function that calls this function needs to return.
1. check may be performed when the session ends.
2. I have not applied for a transaction object. is using a function directly causing an error?
3. Despite the final error, the database has been successfully modified (persistence is complete ).
4. It is the right way to implement it quickly and understand it thoroughly.
5. This change may affect the execution time. Optimization may be required when there is a large amount of data.
Appendix: Detailed stacktrace:
Org. springframework. transaction. TransactionSystemException: cocould not commit Hibernate transaction; nested exception is org. hibernate.TransactionException: Transaction not successfully started
At org. springframework. orm. hibernate3.HibernateTransactionManageR.DoCommit(HibernateTransactionManager. java: 660)
Caused by: org. hibernate. TransactionException: Transaction not successfully started
At org. hibernate. transaction. JDBCTransaction. commit (JDBCTransaction. java: 130)
At org. springframework. orm. hibernate3.HibernateTransactionManager. doCommit (HibernateTransactionManager. java: 656)
... 77 more