Results 1 to 8 of 8

Thread: problem during the declarative transaction

Hybrid View

  1. #1
    Join Date
    Aug 2004
    Location
    Bangalore,India
    Posts
    7

    Default problem during the declarative transaction

    Hi,
    I did changes as per the instruction but still i couldnt
    do transaction rollback using declarative transaction.

    My code is given below

    TestSpringDao.java my dao class where i get the exception
    --------------------------------------------------------------------

    public String myQuery()throws DataAccessException {
    String name = "";

    try {
    jt = new JdbcTemplate();
    jt.setDataSource(dataSource);

    jt.update("update retiredb set name='test12' where Id=1");
    jt.update("insert into spring2 values ('test2','address2')");

    }
    catch (DataAccessException e)
    {
    System.out.println("inside exception DataAccessException ------" + e);
    throw e;
    }
    catch (Exception ee) {
    System.out.println("inside exception Exception ------" + ee);
    }
    return name;

    my buisiness class from where i am calling the daos perticular method
    -------------------------------------------------------------------------------

    public boolean CreateRetirementDataObject(RetirementPlanBean rpb) {

    try {
    ts.myQuery();
    }
    catch (DataAccessException e)
    {
    System.out.println("inside DataAccessException buisiness class ------" + e);

    }
    catch (Exception e) {
    System.out.println("inside exception in buisiness class<<<<<"+e);
    }
    return true;
    }

    and my xml files are look like this
    ----------------------------------------

    <bean id="testSpring" class="beans.TestSpring">
    <property name="dataSource"><ref local="dataSource"/></property>

    </bean>

    <bean id="retirementBusinessObject" class="beans.RetirementBusinessObject">
    <property name="dataAccessObject"><ref local="testSpring"/></property>
    </bean>
    ------------------------------------------------------------------------------


    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSou rceTransactionManager">
    <property name="dataSource"><ref bean="dataSource"/></property>
    </bean>

    <bean id="senderNewTx" class="org.springframework.transaction.interceptor .TransactionProxyFactoryBean">
    <property name="transactionManager">
    <ref bean="transactionManager"/>
    </property>
    <property name="target">
    <ref bean="retirementBusinessObject"/>
    </property>
    <property name="transactionAttributes">
    <props>
    <prop key="*">PROPAGATION_REQUIRED,-DataAccessException</prop>
    </props>
    </property>
    </bean>

    how can i overcome the problem?
    is there any mistakes using the transaction setting done by me?

    Thanking you,
    Biju

  2. #2
    Join Date
    Aug 2004
    Location
    San Mateo, CA
    Posts
    1,265

    Default

    You're still swallowing in the second Exception catch block.

    Please post a reply to an existing thread, rather than create a new thread in the forum.

  3. #3
    Join Date
    Aug 2004
    Location
    Bangalore,India
    Posts
    7

    Default Problem During Declarative transaction

    Hi,
    thak u very much for ur earlier responses

    But still i have the problem.
    I want to inform u that i am using the MSACESS database
    will this create any problem?
    my code look as below now


    TestSpringDao.java my dao class where i get the exception
    --------------------------------------------------------------------

    public String myQuery()throws Exception,DataAccessException {
    String name = "";

    try {
    jt = new JdbcTemplate();
    jt.setDataSource(dataSource);

    jt.update("update retiredb set name='test12' where Id=1");
    jt.update("insert into spring2 values ('test2','address2')");

    }
    catch (DataAccessException e)
    {
    System.out.println("inside exception DataAccessException ------" + e);
    throw e;
    }
    catch (Exception ee) {
    System.out.println("inside exception Exception ------" + ee);
    throw ee;

    }
    return name;

    my buisiness class from where i am calling the daos perticular method
    -------------------------------------------------------------------------------

    public boolean CreateRetirementDataObject(RetirementPlanBean rpb) {

    try {
    ts.myQuery();
    }
    catch (DataAccessException e)
    {
    System.out.println("inside DataAccessException buisiness class ------" + e);

    }
    catch (Exception e) {
    System.out.println("inside exception in buisiness class<<<<<"+e);
    }
    return true;
    }

    and my xml files are look like this
    ----------------------------------------

    <bean id="testSpring" class="beans.TestSpring">
    <property name="dataSource"><ref local="dataSource"/></property>

    </bean>

    <bean id="retirementBusinessObject" class="beans.RetirementBusinessObject">
    <property name="dataAccessObject"><ref local="testSpring"/></property>
    </bean>
    ------------------------------------------------------------------------------


    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSou rceTransactionManager">
    <property name="dataSource"><ref bean="dataSource"/></property>
    </bean>

    <bean id="senderNewTx" class="org.springframework.transaction.interceptor .TransactionProxyFactoryBean">
    <property name="transactionManager">
    <ref bean="transactionManager"/>
    </property>
    <property name="target">
    <ref bean="retirementBusinessObject"/>
    </property>
    <property name="transactionAttributes">
    <props>
    <prop key="*">PROPAGATION_REQUIRED,-DataAccessException,-Exception</prop>
    </props>
    </property>
    </bean>

    I am getting the exception in catch block of DataAccessException .
    Is there is any problem in setting the target for transaction.
    and what actualy the property key "*" means(Is it all the method of that perticular object)

    Thanking you,
    Biju

  4. #4
    Join Date
    Aug 2004
    Location
    Toronto, Canada
    Posts
    736

    Default

    Your business class is still swallowing the DataAccessException.

    The "*" is just a generic regex which will match all methods.

    Regards,
    Colin Sampaleanu
    SpringSource - http://www.springsource.com

  5. #5
    Join Date
    Aug 2004
    Location
    Bangalore,India
    Posts
    7

    Default Problem in using declarative transaction

    Hi,
    thak u very much for ur earlier responses
    As per ur advice i re thrown the exception i am catching in buisiness class
    to the action class.
    But still i have the problem.
    I want to inform u that i am using the MSACESS database will this create any problem?
    my code look as below now


    TestSpringDao.java my dao class where i get the exception
    --------------------------------------------------------------------

    public String myQuery()throws Exception,DataAccessException {
    String name = "";

    try {
    jt = new JdbcTemplate();
    jt.setDataSource(dataSource);

    jt.update("update retiredb set name='test12' where Id=1");
    jt.update("insert into spring2 values ('test2','address2')");

    }
    catch (DataAccessException e)
    {
    System.out.println("inside exception DataAccessException ------" + e);
    throw e;
    }
    catch (Exception ee) {
    System.out.println("inside exception Exception ------" + ee);
    throw ee;

    }
    return name;

    my buisiness class from where i am calling the daos perticular method
    -------------------------------------------------------------------------------

    public boolean CreateRetirementDataObject(RetirementPlanBean rpb)throws Exception,DataAccessException {

    try {
    ts.myQuery();
    }
    catch (DataAccessException e)
    {
    System.out.println("inside DataAccessException buisiness class ------" + e);
    throw e;

    }
    catch (Exception e) {
    System.out.println("inside exception in buisiness class<<<<<"+e);
    throw e;

    }
    return true;
    }

    and my xml files are look like this
    ----------------------------------------

    <bean id="testSpring" class="beans.TestSpring">
    <property name="dataSource"><ref local="dataSource"/></property>

    </bean>

    <bean id="retirementBusinessObject" class="beans.RetirementBusinessObject">
    <property name="dataAccessObject"><ref local="testSpring"/></property>
    </bean>
    ------------------------------------------------------------------------------


    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSou rceTransactionManager">
    <property name="dataSource"><ref bean="dataSource"/></property>
    </bean>

    <bean id="senderNewTx" class="org.springframework.transaction.interceptor .TransactionProxyFactoryBean">
    <property name="transactionManager">
    <ref bean="transactionManager"/>
    </property>
    <property name="target">
    <ref bean="retirementBusinessObject"/>
    </property>
    <property name="transactionAttributes">
    <props>
    <prop key="*">PROPAGATION_REQUIRED,-DataAccessException,-Exception</prop>
    </props>
    </property>
    </bean>

    I am getting the exception in catch block of DataAccessException .

    Is there is any problem in setting the target for transaction.
    what should be the target class which is specifying?
    whether It should be the buisiness class from where i am calling the dao method?


    Thanking you,
    Biju

  6. #6
    Join Date
    Aug 2004
    Location
    Toronto, Canada
    Posts
    736

    Default

    You should be wrapping the business method.

    The best way to get a handle on what is going on is to look at your log. If your catch block in the business method is catching the error, and then rethrowing it, then the transaction should be reacting to that, and the log should show the rollback (or commit, if in fact it's not rolling back, or neither, if in fact you are not even in a transaction).

    Regards,
    Colin Sampaleanu
    SpringSource - http://www.springsource.com

  7. #7
    Join Date
    Aug 2004
    Location
    Bangalore,India
    Posts
    7

    Default Problem while using declarative transaction

    Hi ,
    U mean the method may not be in transaction?
    than what setting i should do to include a method in a transaction?

    The server is not showing any message regarding the transaction except "transactionManager" singleton object is created...

    Thanking you,
    Biju

  8. #8
    Join Date
    Aug 2004
    Location
    Toronto, Canada
    Posts
    736

    Default

    Are you sure you're using the business object through the proxy, which you have called 'senderNewTx', and not directly as the unwrapped business object itself, which you call 'retirementBusinessObject'?

    Normally, if you create wrap a n object transactionally, it's a good idea to use some sort of convention in naming, such as
    adding 'Target' to the name of the raw object to be wrapped, and the simple name for the wrapped version, i.e.
    myServiceTarget - this is the raw object
    myService - this is the same thing wrapped with the proxy factory bean

    The manual in this section:
    http://www.springframework.org/docs/...-concise-proxy
    describes how to wrap target objects as an inner bean, so you can't accidentally use the unwrapped object.

    Regards,
    Colin Sampaleanu
    SpringSource - http://www.springsource.com

Similar Threads

  1. Unit testing with JOTM and JtaTransactionManager
    By lalle in forum Architecture
    Replies: 1
    Last Post: Oct 15th, 2005, 09:05 AM
  2. Replies: 0
    Last Post: Jun 6th, 2005, 06:22 AM
  3. Replies: 3
    Last Post: Nov 19th, 2004, 07:16 PM
  4. Transaction pb Hibernate/MySQL
    By syluser in forum Data
    Replies: 2
    Last Post: Aug 28th, 2004, 02:40 PM
  5. Replies: 1
    Last Post: Aug 19th, 2004, 04:02 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •