Not Rolling Back Spring Transaction From ZK

asked 2015-05-27 16:34:58 +0800

VikasSrivastava gravatar image VikasSrivastava

Dear All , I am facing a problem while calling the service method written in Spring Sevice that is injected in MVVM in that method I am saving one object and after that doing some other value fatching method call that throw exception and I want that while throwing that exception my Transaction rollback my service method part are as under CeilingServiceIMPL

            CeilingSheet ceilingSheet = new CeilingSheet();
    ceilingSheet = saveCeilingSheet(ceilingSheet).getResult();

    CeilingCategory ceilingCategory1 = null;
    try {
        ceilingCategory1 = categoryQueryService.findCeilingCategoryByCode(
    } catch (ObjectNotFoundException ex) {
        throw new RequestException(1234, ceilingCategory1);

if RequestException throws , I am expecting that my record that I saved before also rollback. I have making the service Transaction by annotating as
@Transactional(rollbackFor = RequestException.class)

When I tried this method to call from junit test case it rolling back fine , but when I integrate it with ZK zul page and View Model by autowired services it stop rolling back and even if my code throws RequestException my CeilingSheet are persisting. My ZK web.xml is

<!-- Spring can be easily integrated into any Java-based web framework. 
    All you need to do is to declare the ContextLoaderListener in your web.xml 
    and use a contextConfigLocation <context-param> to set which context files 
    to load. If you don't specify the contextConfigLocation context parameter, 
    the ContextLoaderListener will look for a /WEB-INF/applicationContext.xml 
    file to load. Once the context files are loaded, Spring creates a WebApplicationContext 
    object based on the bean definitions and puts it into the ServletContext. -->


<!-- LOGGER -->

<!-- Loads the Spring web application context -->

<!-- end of spring configuration -->

<description><![CDATA[My ZK Application]]></description>
<display-name>IFMIS User Interface</display-name>

<!-- //// -->
<!-- ZK -->
    <description>ZK listener for session cleanup</description>
    <description>ZK loader for ZUML pages</description>

    <!-- Must. Specifies URI of the update engine (DHtmlUpdateServlet). It 
        must be the same as <url-pattern> for the update engine. -->
    <!-- Optional. Specifies whether to compress the output of the ZK loader. 
        It speeds up the transmission over slow Internet. However, if you configure 
        a filter to post-processing the output, you might have to disable it. Default: 
        true <init-param> <param-name>compress</param-name> <param-value>true</param-value> 
        </init-param> -->
    <!-- [Optional] Specifies the default log level: OFF, ERROR, WARNING, INFO, 
        DEBUG and FINER. If not specified, the system default is used. <init-param> 
        <param-name>log-level</param-name> <param-value>OFF</param-value> </init-param> -->
    <load-on-startup>1</load-on-startup><!-- Must -->
<!-- [Optional] Uncomment it if you want to use richlets. <servlet-mapping> 
    <servlet-name>zkLoader</servlet-name> <url-pattern>/zk/*</url-pattern> </servlet-mapping> -->
    <description>The asynchronous update engine for ZK</description>

    <!-- [Optional] Specifies whether to compress the output of the ZK loader. 
        It speeds up the transmission over slow Internet. However, if your server 
        will do the compression, you might have to disable it. Default: true <init-param> 
        <param-name>compress</param-name> <param-value>true</param-value> </init-param> -->
    <!-- [Optional] Specifies the AU extension for particular prefix. <init-param> 
        <param-name>extension0</param-name> <param-value>/upload=com.my.MyUploader</param-value> 
        </init-param> -->

My application-context.xml

    <property name="locations">

<tx:annotation-driven />

<context:annotation-config />

<context:component-scan base-package="my.service" />

<import resource="hibernate-context.xml" />

<bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"/>


My hibernat-context.xml

<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
    <property name="driverClass">
    <property name="jdbcUrl">
    <property name="user">
    <property name="password">
    <property name="maxPoolSize" value="${jdbc.maxPoolSize}" />
    <property name="minPoolSize" value="${jdbc.minPoolSize}" />
    <property name="maxStatements" value="${jdbc.maxStatements}" />
    <property name="testConnectionOnCheckout" value="${jdbc.testConnection}" />

<!-- bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> 
    <property name="driverClassName"> <value>${driverClassName}</value> </property> 
    <property name="url"> <value>${url}</value> </property> <property name="username"> 
    <value>${username}</value> </property> <property name="password"> <value>${password}</value> 
    </property> </bean -->

<bean id="sessionFactory"
    <property name="dataSource" ref="dataSource" />
    <property name="packagesToScan">
    <property name="hibernateProperties">
            <prop key="hibernate.dialect">${hibernate.dialect}</prop>
            <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
            <prop key="hibernate.format_sql">${hibernate.format_sql}</prop>
            <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
            <prop key="jadira.usertype.autoRegisterUserTypes">${jadira.usertype}</prop>
<bean id="transactionManager"
    <property name="sessionFactory" ref="sessionFactory" />

<bean id="persistenceExceptionTranslationPostProcessor"
    class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />


Please advice ...

delete flag offensive retag edit

4 Answers

Sort by ยป oldest newest most voted

answered 2015-05-29 08:57:47 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16

updated 2015-06-22 10:49:00 +0800

Hmmm, hard to understand what you mean.

Beside that, i'm wondering how you will get the 'RequestException' in your backend.

If you will more than ONE db action under the umbrella from transaction management/rollback than you should ADD a new method for this in your backend which handle the several i.e. save calls.

-- save 1
-- save 2
-- save 3

public void saveMore(Customer customer, Order order){

best Stephan

link publish delete flag offensive edit

answered 2015-05-29 10:00:46 +0800

anutxxas gravatar image anutxxas

Ill try it at home

link publish delete flag offensive edit

answered 2015-06-15 16:48:14 +0800

VikasSrivastava gravatar image VikasSrivastava

Thanks all

I found the solution : Reason : In My application we have the requirement to show the User messages based on the number thrown by the exception , for this we have a separate message-hibernate-context.xml file with seperate

<bean id="transactionManager"
    <property name="sessionFactory" ref="messageSessionFactory" />

and one is already with hibernate-context.xml

    <bean id="transactionManager"
    <property name="sessionFactory" ref="sessionFactory" />

and the above both xml file called from my application-context.xml as

<import resource="hibernate-context.xml" />
<import resource="message-hibernate-context.xml" />

So after code thrown exception based on key thrown , my user-message bean trying to load separate Transaction Manager and old transaction committed and new Hibernate session starts that was going to rollback and since this is new Transaction so It does not found anything to rollback.

Once I removed other Transaction Manager it start working . Thanks All for support...

link publish delete flag offensive edit

answered 2015-06-16 08:19:16 +0800

lewerrkinna gravatar image lewerrkinna

nice, i hope that will work to me

link publish delete flag offensive edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

1 follower



Asked: 2015-05-27 16:34:58 +0800

Seen: 33 times

Last updated: Jun 22 '15

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More