Announcement Announcement Module
Collapse
No announcement yet.
help transacction fail Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • help transacction fail

    I don't understand the handling of transactions. If I have declared


    <bean id="transactionTemplate" abstract="true"
    class="org.springframework.transaction.interceptor .TransactionProxyFactoryBean">
    <property name="transactionManager"><ref bean="transactionManager"/></property>
    <property name="transactionAttributes">
    <props>
    <!-- Los metodos que comiencen por get en los Manager seran readOnly -->
    <prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
    <prop key="insert*">PROPAGATION_REQUIRED</prop>
    <prop key="update*">PROPAGATION_REQUIRED</prop>
    <prop key="delete*">PROPAGATION_REQUIRED</prop>
    </props>
    </property>
    </bean>


    for this code java


    public void insertEdition(EditionVO vo) throws KedrosManagerException, KedrosSQLException, KedrosDAOException {

    //Obtenemos un DAO
    EditionDAO editionDAO = (EditionDAO)DAOFactory.getBeanFactory("EditionDAO" );
    GetLastID lastID = (GetLastID)DAOFactory.getBeanFactory("GetLastID");

    try {


    editionDAO.insertEdition(vo);

    groupEditionDAO.insertGroupEdition(groupEditionVO) ;


    } catch (KedrosSQLException e) {
    throw e;
    } catch (KedrosException e) {
    log.error("########## ERROR en capa MANAGER --> " + e.toString());
    throw new KedrosManagerException(e, "capa MANAGER EditionManager.insertEdition", e.toStringUser());

    }

    and it fails insertGroupedition he/she should not neither be carried out insertEdition

    is this correct?

    }

  • #2
    It's quite hard to make out what's going on there. I would consult the reference manual and have a look at the examples in there. After that if you're still having problems, if you could post back your configuration and code in [code] [ /code] tags, it would be most appreciated.
    http://www.springframework.org/docs/...on-declarative

    Comment


    • #3
      Is what I don't understand the transactions delarativas lack he/she doesn't make make the rollback in the code java?.

      It is Correct my code should not please insert edition answers me to that

      Comment


      • #4
        Hello to all, Not you if I am making it well or wrong has configured the transactions with Propagation_required for this method. but it doesn't work. My version is 1.2.8


        If it fails insertGroupedition the method insertEdition it follows it making there is not rollback. With the propagation_required lack does make another method???? . Do I have to put something in the code java so that he/she makes that rollback??????

        Comment


        • #5
          If you want that insertEdition() method to be transactional then if one of the method calls inside it fails, then all operation in that method will be rollback-ed.
          If you can post more details (complete config file, test code), maybe we can help you more with this problem. Also, please post your code inside [ CODE][ /CODE] tags.

          Comment


          • #6
            It would also help to know exactly what the problem is you are having.

            Comment


            • #7
              This is the problem :
              ROLLBACK doesn't take place in the database. The registration edition is inserted when he/she should not make it however any error log it doesn't exist. Do these transactions of Spring really work?, Please help me

              Edition Manager :

              private EditionDAO editionDAO;

              public void setEditionDAO(EditionDAO editionDAO) throws KedrosDAOException {
              this.editionDAO = (EditionDAO) DAOFactory.getBeanFactory("EditionDAO");
              }

              public EditionDAO getEditionDAO() {
              return editionDAO;
              }






              public void insertEdition(EditionVO vo) throws Exception {

              GroupEditionVO groupEditionVO = new GroupEditionVO(new Integer(lastID.generateId("GROUP_EDITION")),
              vo.getEditionName(), vo.getEditionId());
              GetLastID lastID = (GetLastID)DAOFactory.getBeanFactory("GetLastID");


              getEditionDAO().insertEdition(vo);

              int i=10/0;

              groupEditionDAO.insertGroupEdition(groupEditionVO) ;

              }


              The configuration of the transaction :

              <bean id="transactionTemplate2" abstract="true"
              class="org.springframework.transaction.interceptor .TransactionProxyFactoryBean">
              <property name="transactionManager">
              <ref bean="transactionManager" />
              </property>
              <property name="transactionAttributes">
              <props>
              <prop key="insert*">PROPAGATION_REQUIRED</prop>
              </props>
              </property>
              </bean>



              The log

              [23 jul 2007 15:06:34] RuleBasedTransactionAttribute (DEBUG) - Applying rules to determine whether transaction should rollback on java.lang.ArithmeticException: / by zero
              [23 jul 2007 15:06:34] RuleBasedTransactionAttribute (DEBUG) - Winning rollback rule is: null
              [23 jul 2007 15:06:34] RuleBasedTransactionAttribute (DEBUG) - No relevant rollback rule found: applying superclass default
              [23 jul 2007 15:06:34] TransactionInterceptor (DEBUG) - Invoking rollback for transaction on es.satec.kedros.datos.manager.EditionManager.inser tEdition due to throwable [java.lang.ArithmeticException: / by zero]
              [23 jul 2007 15:06:34] DataSourceTransactionManager (DEBUG) - Triggering beforeCompletion synchronization
              [23 jul 2007 15:06:34] TransactionSynchronizationManager (DEBUG) - Removed value [org.springframework.jdbc.datasource.ConnectionHold er@1d592a] for key [org.springframework.jdbc.datasource.TransactionAwa reDataSourceProxy@24c672] from thread [main]
              [23 jul 2007 15:06:34] DataSourceUtils (DEBUG) - Returning JDBC Connection to DataSource
              [23 jul 2007 15:06:34] TransactionSynchronizationManager (DEBUG) - Retrieved value [org.springframework.jdbc.datasource.ConnectionHold er@19299f5] for key [org.springframework.jdbc.datasource.DriverManagerD ataSource@6078e7] bound to thread [main]
              [23 jul 2007 15:06:34] TransactionSynchronizationManager (DEBUG) - Removed value [org.springframework.jdbc.datasource.ConnectionHold er@d37b87] for key [org.springframework.jdbc.datasource.TransactionAwa reDataSourceProxy@13b625b] from thread [main]
              [23 jul 2007 15:06:34] DataSourceUtils (DEBUG) - Returning JDBC Connection to DataSource
              [23 jul 2007 15:06:34] TransactionSynchronizationManager (DEBUG) - Retrieved value [org.springframework.jdbc.datasource.ConnectionHold er@71949b] for key [org.springframework.jdbc.datasource.DriverManagerD ataSource@1b67d6a] bound to thread [main]
              [23 jul 2007 15:06:34] TransactionSynchronizationManager (DEBUG) - Removed value [org.springframework.jdbc.datasource.ConnectionHold er@75c744] for key [org.springframework.jdbc.datasource.TransactionAwa reDataSourceProxy@fbf51d] from thread [main]
              [23 jul 2007 15:06:34] DataSourceUtils (DEBUG) - Returning JDBC Connection to DataSource
              [23 jul 2007 15:06:34] TransactionSynchronizationManager (DEBUG) - Retrieved value [org.springframework.jdbc.datasource.ConnectionHold er@f62eba] for key [org.springframework.jdbc.datasource.DriverManagerD ataSource@19977bd] bound to thread [main]
              [23 jul 2007 15:06:34] DataSourceTransactionManager (DEBUG) - Initiating transaction rollback
              [23 jul 2007 15:06:34] DataSourceTransactionManager (DEBUG) - Rolling back JDBC transaction on Connection [com.mysql.jdbc.Connection@117c0eb]
              [23 jul 2007 15:06:34] DataSourceTransactionManager (DEBUG) - Triggering afterCompletion synchronization
              [23 jul 2007 15:06:34] TransactionSynchronizationManager (DEBUG) - Removed value [org.springframework.jdbc.datasource.ConnectionHold er@19299f5] for key [org.springframework.jdbc.datasource.DriverManagerD ataSource@6078e7] from thread [main]
              [23 jul 2007 15:06:34] DataSourceUtils (DEBUG) - Returning JDBC Connection to DataSource
              [23 jul 2007 15:06:34] TransactionSynchronizationManager (DEBUG) - Removed value [org.springframework.jdbc.datasource.ConnectionHold er@71949b] for key [org.springframework.jdbc.datasource.DriverManagerD ataSource@1b67d6a] from thread [main]
              [23 jul 2007 15:06:34] DataSourceUtils (DEBUG) - Returning JDBC Connection to DataSource
              [23 jul 2007 15:06:34] TransactionSynchronizationManager (DEBUG) - Removed value [org.springframework.jdbc.datasource.ConnectionHold er@f62eba] for key [org.springframework.jdbc.datasource.DriverManagerD ataSource@19977bd] from thread [main]
              [23 jul 2007 15:06:34] DataSourceUtils (DEBUG) - Returning JDBC Connection to DataSource
              [23 jul 2007 15:06:34] TransactionSynchronizationManager (DEBUG) - Clearing transaction synchronization
              [23 jul 2007 15:06:34] TransactionSynchronizationManager (DEBUG) - Removed value [org.springframework.jdbc.datasource.ConnectionHold er@15d4273] for key [org.springframework.jdbc.datasource.DriverManagerD ataSource@1486306] from thread [main]
              [23 jul 2007 15:06:34] DataSourceTransactionManager (DEBUG) - Releasing JDBC Connection [com.mysql.jdbc.Connection@117c0eb] after transaction
              [23 jul 2007 15:06:34] DataSourceUtils (DEBUG) - Returning JDBC Connection to DataSource
              Last edited by amarques; Jul 23rd, 2007, 09:13 AM.

              Comment


              • #8
                Can you post a more complete configuration ?

                Comment


                • #9
                  This is the whole configuration. The system detects the error like leave in the log but he/she doesn't make rollback. I believe that Spring doesn't work.

                  ************************************************** *******

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


                  <bean id="transactionTemplate2" abstract="true"
                  class="org.springframework.transaction.interceptor .TransactionProxyFactoryBean">
                  <property name="transactionManager">
                  <ref bean="transactionManager" />
                  </property>
                  <property name="transactionAttributes">
                  <props>
                  <!-- Los metodos que comiencen por get en los Manager seran readOnly
                  <prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>-->
                  <prop key="*AfterValidation">PROPAGATION_REQUIRED</prop>
                  <prop key="insert*">PROPAGATION_REQUIRED</prop>
                  </props>
                  </property>
                  </bean>

                  ************************************************** *******

                  <bean id="EditionManager" parent="transactionTemplate2">
                  <property name="target">
                  <bean class="es.satec.kedros.datos.manager.EditionManage r">
                  <property name="editionDAO">
                  <ref bean="EditionDAO" />
                  </property>
                  </bean>
                  </property>
                  </bean>

                  ************************************************** *******


                  <bean id="EditionDAO"
                  class="es.satec.kedros.datos.dao.edition.EditionDA OImpl">
                  <property name="sqlMapClient" ref="sqlMapClient" />
                  </bean>

                  Comment


                  • #10
                    Even if you're setting editionDAO in your config file through DI, inside your method you get another editionDAO:
                    Code:
                     EditionDAO editionDAO = (EditionDAO)DAOFactory.getBeanFactory("EditionDAO" );

                    Comment


                    • #11
                      apologize but that error already corrected it:


                      private EditionDAO editionDAO;

                      public void setEditionDAO(EditionDAO editionDAO) throws KedrosDAOException {
                      this.editionDAO = (EditionDAO) DAOFactory.getBeanFactory("EditionDAO");
                      }

                      public EditionDAO getEditionDAO() {
                      return editionDAO;
                      }






                      public void insertEdition(EditionVO vo) throws Exception {

                      GroupEditionVO groupEditionVO = new GroupEditionVO(new Integer(lastID.generateId("GROUP_EDITION")),
                      vo.getEditionName(), vo.getEditionId());
                      GetLastID lastID = (GetLastID)DAOFactory.getBeanFactory("GetLastID");


                      getEditionDAO().insertEdition(vo);

                      int i=10/0;

                      groupEditionDAO.insertGroupEdition(groupEditionVO) ;

                      }


                      This is the code that this really: and it doesn't work

                      Comment


                      • #12
                        Your transaction configuration looks ok to me.
                        My best guess is that you are using another connection, which Spring doesn't manage it, to actually insert something in database.
                        You have to work with the same data source as defined for your transaction manager. This code:
                        public void setEditionDAO(EditionDAO editionDAO) throws KedrosDAOException {
                        this.editionDAO = (EditionDAO) DAOFactory.getBeanFactory("EditionDAO");
                        }
                        uses an editionDAO which have a SqlMapClientDaoSupport (I'm just assuming your DAOs extend SqlMapClientDaoSupport) that uses the same data-source defined in your config file ?

                        Later edit:
                        and please use [ CODE][ /CODE] (without spaces) tags when posting your source code.

                        Comment


                        • #13
                          Another edition instance doesn't exist.

                          Code:
                          EditionDAOImpl 
                          
                           /**
                            * The Class EditionDAOImpl.
                            */
                          public class EditionDAOImpl extends SqlMapClientDaoSupport implements EditionDAO {
                           
                           
                           
                           public void insertEdition(EditionVO vo) throws KedrosSQLException, KedrosDAOException {
                          
                          	try {
                          	    if (log.isDebugEnabled())
                          		log.debug("##-------- VO de ediciones a insertar en BBDD" + vo.toString());
                          
                          	    // Insertamos el registro editionId con los datos del vo
                          	    getSqlMapClientTemplate().insert("insertEdition", vo);
                          
                          	} catch (DataIntegrityViolationException e) {
                          	    if (log.isDebugEnabled())
                          		log
                          			.error("########## ERROR en capa EditionDAOImpl.insertEdition preparando un INSERT. Causa: --> "
                          				+ e.toString() + e.getCause());
                          	    throw new KedrosSQLException(e, "Error en capa DAO EditionDAOImpl.insertEdition", e.getMessage());
                          
                          	} catch (Exception e) {
                          	    if (log.isDebugEnabled())
                          		log
                          			.error("########## ERROR en capa EditionDAOImpl.insertEdition preparando un INSERT. Causa: --> "
                          				+ e.toString() + e.getCause());
                          	    throw new KedrosDAOException(e, "Error en capa DAO EditionDAOImpl.insertEdition", e.getMessage());
                          
                          	}
                              }

                          sees the log any log.error doesn't exist and it demonstrates that spring detects the error and it executes the transacion.


                          Code:
                           
                          [23 jul 2007 15:06:34] RuleBasedTransactionAttribute (DEBUG) - Applying rules to determine whether transaction should rollback on java.lang.ArithmeticException: / by zero
                          [23 jul 2007 15:06:34] RuleBasedTransactionAttribute (DEBUG) - Winning rollback rule is: null
                          [23 jul 2007 15:06:34] RuleBasedTransactionAttribute (DEBUG) - No relevant rollback rule found: applying superclass default
                          [23 jul 2007 15:06:34] TransactionInterceptor (DEBUG) - Invoking rollback for transaction on es.satec.kedros.datos.manager.EditionManager.insertEdition due to throwable [java.lang.ArithmeticException: / by zero]
                          [23 jul 2007 15:06:34] DataSourceTransactionManager (DEBUG) - Triggering beforeCompletion synchronization
                          [23 jul 2007 15:06:34] TransactionSynchronizationManager (DEBUG) - Removed value [org.springframework.jdbc.datasource.ConnectionHolder@1d592a] for key [org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy@24c672] from thread [main]
                          [23 jul 2007 15:06:34] DataSourceUtils (DEBUG) - Returning JDBC Connection to DataSource
                          [23 jul 2007 15:06:34] TransactionSynchronizationManager (DEBUG) - Retrieved value [org.springframework.jdbc.datasource.ConnectionHolder@19299f5] for key [[email protected]7] bound to thread [main]
                          [23 jul 2007 15:06:34] TransactionSynchronizationManager (DEBUG) - Removed value [org.springframework.jdbc.datasource.ConnectionHolder@d37b87] for key [org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy@13b625b] from thread [main]
                          [23 jul 2007 15:06:34] DataSourceUtils (DEBUG) - Returning JDBC Connection to DataSource
                          [23 jul 2007 15:06:34] TransactionSynchronizationManager (DEBUG) - Retrieved value [org.springframework.jdbc.datasource.ConnectionHolder@71949b] for key [[email protected]6a] bound to thread [main]
                          [23 jul 2007 15:06:34] TransactionSynchronizationManager (DEBUG) - Removed value [org.springframework.jdbc.datasource.ConnectionHolder@75c744] for key [org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy@fbf51d] from thread [main]
                          [23 jul 2007 15:06:34] DataSourceUtils (DEBUG) - Returning JDBC Connection to DataSource
                          [23 jul 2007 15:06:34] TransactionSynchronizationManager (DEBUG) - Retrieved value [org.springframework.jdbc.datasource.ConnectionHolder@f62eba] for key [[email protected]bd] bound to thread [main]
                          [23 jul 2007 15:06:34] DataSourceTransactionManager (DEBUG) - Initiating transaction rollback
                          [23 jul 2007 15:06:34] DataSourceTransactionManager (DEBUG) - Rolling back JDBC transaction on Connection [com.mysql.jdbc.Connection@117c0eb]
                          [23 jul 2007 15:06:34] DataSourceTransactionManager (DEBUG) - Triggering afterCompletion synchronization
                          [23 jul 2007 15:06:34] TransactionSynchronizationManager (DEBUG) - Removed value [org.springframework.jdbc.datasource.ConnectionHolder@19299f5] for key [[email protected]7] from thread [main]
                          [23 jul 2007 15:06:34] DataSourceUtils (DEBUG) - Returning JDBC Connection to DataSource
                          [23 jul 2007 15:06:34] TransactionSynchronizationManager (DEBUG) - Removed value [org.springframework.jdbc.datasource.ConnectionHolder@71949b] for key [[email protected]6a] from thread [main]
                          [23 jul 2007 15:06:34] DataSourceUtils (DEBUG) - Returning JDBC Connection to DataSource
                          [23 jul 2007 15:06:34] TransactionSynchronizationManager (DEBUG) - Removed value [org.springframework.jdbc.datasource.ConnectionHolder@f62eba] for key [[email protected]bd] from thread [main]
                          [23 jul 2007 15:06:34] DataSourceUtils (DEBUG) - Returning JDBC Connection to DataSource
                          [23 jul 2007 15:06:34] TransactionSynchronizationManager (DEBUG) - Clearing transaction synchronization
                          [23 jul 2007 15:06:34] TransactionSynchronizationManager (DEBUG) - Removed value [org.springframework.jdbc.datasource.ConnectionHolder@15d4273] for key [[email protected]06] from thread [main]
                          [23 jul 2007 15:06:34] DataSourceTransactionManager (DEBUG) - Releasing JDBC Connection [com.mysql.jdbc.Connection@117c0eb] after transaction
                          [23 jul 2007 15:06:34] DataSourceUtils (DEBUG) - Returning JDBC Connection to DataSource

                          but the rollback is not executed
                          Last edited by amarques; Jul 23rd, 2007, 09:38 AM.

                          Comment

                          Working...
                          X