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

  • SEARCH
  • Home
  • 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 8992675
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:00:48+00:00 2026-06-15T23:00:48+00:00

I am having a doubt in exception handling with a Transaction. To state clearly

  • 0

I am having a doubt in exception handling with a Transaction. To state clearly my problem I would like to show my configuration:

<bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory" />
</bean>

<tx:annotation-driven transaction-manager="transactionManager" />

<bean id="transactionInterceptor" abstract="true" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
    <property name="transactionManager" ref="transactionManager" />
    <property name="transactionAttributeSource">
        <bean class="org.springframework.transaction.annotation.AnnotationTransactionAttributeSource" />
    </property>
</bean>

<bean id="baseService" abstract="true">
    <property name="daoProvider" ref="daoProvider" />
</bean>

<bean id="customerService" parent="transactionInterceptor">
    <property name="target">
        <bean class="com.edfx.adb.service.CustomerService" parent="baseService" />
    </property>
</bean>

<bean id="daoProvider" class="com.edfx.adb.dao.provider.DaoProvider">   
    <property name="customerDao" ref="customerDao" />
</bean>

<bean id="customerDao" class="com.edfx.adb.dao.CustomerDao">
    <constructor-arg value="#{T(com.edfx.adb.persist.entity.Customer)}" />
    <property name="sessionFactory" ref="sessionFactory" />
</bean>

The active transaction class is:

@Transactional
public class CustomerService extends BaseService implements ICustomerService {

    @Transactional(readOnly = true)
    public Customer getCustomerById(String id) {
        return getDaoProvider().getCustomerDao().getCustomerById(id);
    }

    @Transactional(readOnly = false, propagation = Propagation.REQUIRED, rollbackFor = { Throwable.class })
    public void addNewCustomer(CustomerDTO customerDTO) {
        Customer customer = new Customer();

        customer.setCustomerId(customerDTO.getCustomerId());
        customer.setCustomerName(customerDTO.getCustomerName());
        customer.setActive(customerDTO.isActive());

        getDaoProvider().getCustomerDao().save(customer);
    }
}

My doubts lies in the method addNewCustomer. I have set rollbackFor = { Throwable.class }.

How does it work?

Also do I need to explicitly handle exception like:

@Transactional(readOnly = false, propagation = Propagation.REQUIRED, rollbackFor = { Throwable.class })
public boolean addNewCustomer(CustomerDTO customerDTO) {
    Customer customer = new Customer();

    customer.setCustomerId(customerDTO.getCustomerId());
    customer.setCustomerName(customerDTO.getCustomerName());
    customer.setActive(customerDTO.isActive());

    try {
        getDaoProvider().getCustomerDao().save(customer);
    } catch (Throwable throwable) {
        return false;
    }

    return true;
}

Forcefully I have created an exception by deleting a column from the customer table, BUT that exception wasn’t catch in the try-catch block, rather I can catch that exception from the managed bean where I have invoked the addNewCustomer method.

  • 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-15T23:00:49+00:00Added an answer on June 15, 2026 at 11:00 pm

    This is an excerpt from Spring docs

    In its default configuration, the Spring Framework’s transaction
    infrastructure code only marks a transaction for rollback in the case
    of runtime, unchecked exceptions; that is, when the thrown exception
    is an instance or subclass of RuntimeException. (Errors will also – by
    default – result in a rollback). Checked exceptions that are thrown
    from a transactional method do not result in rollback in the default
    configuration.

    You set rollbackFor = Throwable.class, now Spring will rollback for any Exception / Error. By default, whether we like it or not, Spring will rollback only for RuintimeException, and commit otherwise

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

Sidebar

Related Questions

I'm new to Grails, and having a problem that is no doubt trivial, but
When in doubt, turn to Stackoverflow... I'm having a problem with string allocation. My
Hi does Apples iOS is having backward compatability? I'm having a doubt like in
I have a doubt. There are 10 different threads in runnable state. Each having
I build a parsing algorithm using NSXMLParser. Im having doubt as to what is
I'm having one doubt about the VIM ENCRYPTION key . I having a text
I am having a doubt about the working of the HTTP protocol. We know
I am novice in hibernate. i am having a doubt regarding transactions and flushing..
having this two classes I always have a doubt of which is the best
No doubt elements of this question have been asked before, but I'm having trouble

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.