Don ' t flush the Session after an exception occurs

Source: Internet
Author: User

A few days ago the operation of the project on the production environment took place a "don ' t flush the Session after an exception occurs" anomaly, in the online search for a lot of information, found that the talk is quite waste wood, because all are based on their own problems to talk about the solution, There is no telling what is "don ' t flush the session after an exception occurs", why does the "don ' t flush the session after an exception occurs", in fact this An exception is an exception that is defined within hibernate, and the reason for this exception is that you used a session that has already been presented with an error, that is, the session has an error, and the session is used. The second time you use this session, you will be quoted "Don ' t flush the session after an exception occurs".


Now analyze why I am reporting this exception:

@Scheduled (cron = "0 30 0 * *?")
@Transactional
public void Schedulegetvmsurveryinfo () {
try {
Hostmonitorservice.dovmsurveryinfo ("LINUX", 100);
Hostmonitorservice.dovmsurveryinfo ("WINDOWS", 100);
} catch (Exception e) {
Logger.error ("Scheduleserviceimpl call Schedulegetvmsurveryinfo out exception, the message is:" + e.getmessage ());
}
}


Dovmsurveryinfo method also added @Transactional, because my internal bottom operation HQL get session is Getcurentsession (), so "Linux" and "Windows" Two operations using the same session, in the Linux operation, the session error (Reason my database name field allocation of bytes only 20, the actual data is very large, not enough, so the session error), and so on "windows" operation, or use the session, because Seesion has reported an error, so will report "don ' t flush the Session after an exception occurs" This mistake, I this workaround is: give the name byte to allocate a bit larger, second: give " Linux "and" Windows "each assign a transaction, so that two will use a different session, the error will not occur.


I'm writing this blog just to show why I'm reporting "don ' t flush the Session after an exception occurs" error, what this error is. My example does not have to understand, I write is not very whole.

Don ' t flush the Session after an exception occurs

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.