Announcement Announcement Module
Collapse
No announcement yet.
problem during the declarative transaction Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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.

    Comment


    • #3
      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

      Comment


      • #4
        Your business class is still swallowing the DataAccessException.

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

        Regards,

        Comment


        • #5
          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

          Comment


          • #6
            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,

            Comment


            • #7
              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

              Comment


              • #8
                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,

                Comment

                Working...
                X