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 开发者_JAVA技巧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 (i.e. non-transactional), that's the reason the "transaction" was not rollbacked (i.e. 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
精彩评论