An unexpected spring transaction failure trace (transaction does not roll)

Source: Internet
Author: User

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.

    1. SPRINGMVC context, conflict with service context

    2. Data table does not support transactions (MySQL MyISAM)

    3. 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)

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.