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