Hibernate: cocould not toggle autocommit case 1

Source: Internet
Author: User

A problem occurred in the project a few days ago: When submitting data on the page, the following error occurs: cocould not toggle autocommit, org. hibernate. sessionexception: Session is close.

The project structure is spring + hibernate.

The following describes how to handle the problem:

 

Solution 1

I found a buddy on the internet saying that he wants to change the configuration file:

Remove Connection. autocommit = true of hibernate. cfg. xml ....

 

I checked the configuration file and did not set this item. This solution does not suit my situation.

 

Solution 2

Find a Robbin article on the Internet about how to analyze transaction in hibernateArticle

URL: http://www.javaeye.com/topic/264#806

After reading it, I learned the bottom layer of hibernate.Code.

 

Solution 3

No way. I checked my code again and carefully. We found that:

After opensession () is followed by closesession (), this should be caused by a mistake in writing code. It is too careless!

After modification, the problem does not recur.

 

Reflection:

1. Being careful is very important. As the saying goes, Details determine success or failure.

2 open-source frameworks such as Hibernate and spring should be consciously viewed in applicationsSource codeTo understand the underlying

 

 

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.