Weekend, and tinker with the spring business. Spring transaction configuration is very simple, which is the spring advantage. But the problem is, do not know the principle, encountered some problems, it is flying blind. I was just a fool once.
There are several main categories of answers to search for when tracking problems.
-
SPRINGMVC context, conflict with service context
-
Data table does not support transactions (MySQL MyISAM)
-
Exception type, which supports runtimeexception by default and requires special configuration if other exceptions
My question, none of the above reasons. I'm sorry.
@Transactional (isolation= isolation.read_committed, rollbackfor={exception.class, Runtimeexception.class}) Public int saveblog (Blog blog) { int blogId=0; try { blogid = this.blogdao.save (blog); event Event = new event (); event.seteventdate (new date ()); string eventstr= messageformat.format ( "This is a event from blog {0}", blogid); event.settitle (EVENTSTR); if (Blog.getTitle (). Contains ("error")) { throw new exception ("Simulated failure condition, manual trigger Exception");   &NBsp; } this.eventdao.save (event); } finally { return blogid; }}
I forced the return ID in order to facilitate test result validation. Use finally.
During the trace log process, it was found that the exception information was not printed and was ignored. Very strange. If you remove finally, the exception stack is printed normally.
The way to fix it is obviously to remove the try finally structure.
This article is from a "simple" blog, so be sure to keep this source http://dba10g.blog.51cto.com/764602/1923434
An unexpected spring transaction failure trace (transaction does not roll)