Solve Hibernate errors (TransactionException: Transactionnotsuccess

Source: Internet
Author: User
[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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.