简体   繁体   中英

Spring 3.0: SQL not committed when exception is thrown

I am working on a Java - Spring 3.0 - Hibernate Annotations app.

Everything worked OK until I switched to another MySQL database server.

In the first one, when an exception was thrown, the SQL was committed and saved to the DB. (That is what I want).

In the second MySQL server (the new one), when an exception is thrown, all the DB updates are lost.

What can I be doing wrong? Isn't commit-on-exception an application feature (as opposed as a db feature)? How come MySQL server "knows" if an exception was thrown after all those SQLs?

i dont know about every mysql storage engines. but, commit and roll back are cannot be perform in all engines. InnoDB Storage Engine support these operation.

It would appear that your application code was unwittingly relying on the default auto-commit behaviour of the database server it was talking to. Transaction behaviour on exception is a complex topic, and it may have been working by accident rather than by design.

Consider this an ideal opportunity to expose the bug and fix it, since now you have reproducible test cases.

A little embarrassing but the issue is that in my first server all the tables where myisam (ie non-transactional), that's the reason the "transaction" was not rollbacked (ie no transactions could ever be rollbacked at all).

Once I moved to the new server I discovered this bug and correctly configured the no-rollback-for property in my context file and everything is now ok.

I call this programming by miracle

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM