Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8696663
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:19:38+00:00 2026-06-13T01:19:38+00:00

When service thown an exception that is configured to rollback (rollbackfor), this rollback not

  • 0

When service thown an exception that is configured to rollback (rollbackfor), this rollback not working.

Service class:

@Service("bookService")
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = { BusinessException.class }, readOnly = true)
public class BookServiceImpl implements BookService {

    @Autowired
    private BookRepository bookDAO;

     @Override
     @Transactional(readOnly = false)
     public void transactionTest(Book book) throws BusinessException {
          try {
               bookDAO.test(book);
          } catch (DAOException e) {
               throw new BusinessException("test rollback - service");
          }
     }
}

Repository class:

@Repository("bookRepository")
public class BookRepositoryImpl implements BookRepository {

    @Autowired
    private SessionFactory sessionFactory;

@Transactional(readOnly = false)
@Override
public Book saveOrUpdate(Book book) {
    if (book.getId() != null) {
        getSession().merge(book);
    } else {
        getSession().save(book);
    }
    return book;
}

@Transactional(readOnly = false)
@Override
public void test(Book book) throws DAOException {

    saveOrUpdate(book);
    System.out.println(book.getTitle() + " inserted!");
    throw new DAOException("Test rollback");
}

}

There are one situation that rollback works. To this, I need change BookServiceImpl removing readOnly = true and removing “@Transactional(readOnly = false)” of the “transactionTest” method. But for security reasons I wish use readOnly = true for all class and specify what is method use readOnly = false

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T01:19:39+00:00Added an answer on June 13, 2026 at 1:19 am

    currently for whole BookServiceImpl transaction configuration is @Transactional(propagation = Propagation.REQUIRED, rollbackFor = { BusinessException.class }, readOnly = true)

    and for transactionTest overridden annotation is @Transactional(readOnly = false), when you override annotation with class to method whole annotation updated instead of just specified attribute.

    instead of this you should have below as code for BookServiceImpl

    @Service("bookService")
    @Transactional(readOnly = true)
    public class BookServiceImpl implements BookService {
    
        @Autowired
        private BookRepository bookDAO;
    
         @Override
         @Transactional(propagation = Propagation.REQUIRED, rollbackFor = { BusinessException.class },readOnly = false)
         public void transactionTest(Book book) throws BusinessException {
              try {
                   bookDAO.test(book);
              } catch (DAOException e) {
                   throw new BusinessException("test rollback - service");
              }
         }
    }
    

    and further if you want same kind of transaction on DAO (Repository) level then specify it or just let service to take care about transaction (assuming repository are not going to be directly interfaced with client).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

@Service @Repository @Transactional public class VideoService { @PersistenceContext EntityManager entityManager; public void save(Video video)
If an error/exception occurs in a repository class, should that exception get a. caught
I have a Windows-Forms Application that I configured to use with an ASP.NET Service
I have a WCF service that uses a reference to a class library. Classes
This code is working sorry if any error on the copy paste public class
I get the following unhandled exception thrown from my web service - this isn't
I have a windows service that is, intermittently, throwing an exception that sometimes kills
My service code resided in OnStart() throws Exception(I) and service is stopped. I don't
My service communicates with a server that manages accounts. Each Account has a cap
That's a horrible title, sorry. Here's the scenario: WCF Service uses LINQ to get

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.