Results 1 to 7 of 7

Thread: Transaction not work!!!!

  1. #1
    Join Date
    Jun 2005
    Location
    Italy
    Posts
    16

    Default Transaction not work!!!!

    Hi,
    I use Spring 1.2.1 + Ibatis 2.1.0.
    I've create Pojo, DAO, Manager like Spring manual.
    Plus, i've created a Top manager that contains my manger:
    Action -- > TopMANAGER -->Manager1,2,3,4,n -->DAO1,2,3,n --> POJO1,2,3,4,n

    Ok?

    The TOPMANAGER in applicationContext is called lookupManager

    So, the problem is tihs:
    I call in my action the TopManager, next i have all my manager under a global transaction and i will work good! It is correct?

    The problem appears when i insert a record in 2 tables (Manager) and the last table retrive me an error. The first table's record is committed! (it should be rolledback!!!).

    I post my applicationContext and the error:


    <beans>
    <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryB ean">
    <property name="jndiName">
    <value>java:comp/env/jdbc/repartoweb</value>
    </property>
    </bean>

    <!-- Transaction manager for iBATIS DAOs -->
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSou rceTransactionManager">
    <property name="dataSource"><ref bean="dataSource"/></property>
    </bean>

    <bean id="dataSourceIbatis" class="org.springframework.jdbc.datasource.Transac tionAwareDataSourceProxy">
    <property name="targetDataSource"><ref local="dataSource"/></property>
    </bean>


    <!-- SqlMap setup for iBATIS Database Layer -->
    <bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClient FactoryBean">
    <property name="dataSource"><ref bean="dataSourceIbatis"/></property>
    <property name="configLocation">
    <value>classpath:/ibatis/config/SqlMapConfig.xml</value>
    </property>
    </bean>


    <bean id="accessOperationDAO" class="it.axiosinformatica.webward.database.implem entations.AccessOperationSqlMapDao">
    <!--property name="dataSource"><ref bean="dataSourceIbatis"/></property-->
    <property name="sqlMapClient"><ref bean="sqlMapClient"/></property>
    </bean>

    <bean id="accessDAO" class="it.axiosinformatica.webward.database.implem entations.AccessSqlMapDao">
    <!--property name="dataSource"><ref bean="dataSourceIbatis"/></property-->
    <property name="sqlMapClient"><ref bean="sqlMapClient"/></property>
    </bean>

    <bean id="baseParameterDAO" class="it.axiosinformatica.webward.database.implem entations.BaseParameterSqlMapDao">
    <!--property name="dataSource"><ref bean="dataSourceIbatis"/></property-->
    <property name="sqlMapClient"><ref bean="sqlMapClient"/></property>
    </bean>

    <bean id="bedDAO" class="it.axiosinformatica.webward.database.implem entations.BedSqlMapDao">
    <!--property name="dataSource"><ref bean="dataSourceIbatis"/></property-->
    <property name="sqlMapClient"><ref bean="sqlMapClient"/></property>
    </bean>

    <bean id="courseDAO" class="it.axiosinformatica.webward.database.implem entations.CourseSqlMapDao">
    <!--property name="dataSource"><ref bean="dataSourceIbatis"/></property-->
    <property name="sqlMapClient"><ref bean="sqlMapClient"/></property>
    </bean>

    <bean id="dietComponentsDAO" class="it.axiosinformatica.webward.database.implem entations.DietComponentsSqlMapDao">
    <!--property name="dataSource"><ref bean="dataSourceIbatis"/></property-->
    <property name="sqlMapClient"><ref bean="sqlMapClient"/></property>
    </bean>

    <bean id="dietDAO" class="it.axiosinformatica.webward.database.implem entations.DietSqlMapDao">
    <!--property name="dataSource"><ref bean="dataSourceIbatis"/></property-->
    <property name="sqlMapClient"><ref bean="sqlMapClient"/></property>
    </bean>

    <bean id="extraKindDAO" class="it.axiosinformatica.webward.database.implem entations.ExtraKindSqlMapDao">
    <!--property name="dataSource"><ref bean="dataSourceIbatis"/></property-->
    <property name="sqlMapClient"><ref bean="sqlMapClient"/></property>
    </bean>

    <bean id="fastDAO" class="it.axiosinformatica.webward.database.implem entations.FastSqlMapDao">
    <!--property name="dataSource"><ref bean="dataSourceIbatis"/></property-->
    <property name="sqlMapClient"><ref bean="sqlMapClient"/></property>
    </bean>

    <bean id="functionOperationDAO" class="it.axiosinformatica.webward.database.implem entations.FunctionOperationSqlMapDao">
    <!--property name="dataSource"><ref bean="dataSourceIbatis"/></property-->
    <property name="sqlMapClient"><ref bean="sqlMapClient"/></property>
    </bean>

    <bean id="functionDAO" class="it.axiosinformatica.webward.database.implem entations.FunctionSqlMapDao">
    <!--property name="dataSource"><ref bean="dataSourceIbatis"/></property-->
    <property name="sqlMapClient"><ref bean="sqlMapClient"/></property>
    </bean>

    <bean id="hiddenParamDAO" class="it.axiosinformatica.webward.database.implem entations.HiddenParamSqlMapDao">
    <!--property name="dataSource"><ref bean="dataSourceIbatis"/></property-->
    <property name="sqlMapClient"><ref bean="sqlMapClient"/></property>
    </bean>

    <bean id="languageDAO" class="it.axiosinformatica.webward.database.implem entations.LanguageSqlMapDao">
    <!--property name="dataSource"><ref bean="dataSourceIbatis"/></property-->
    <property name="sqlMapClient"><ref bean="sqlMapClient"/></property>
    </bean>

    <bean id="mealDAO" class="it.axiosinformatica.webward.database.implem entations.MealSqlMapDao">
    <!--property name="dataSource"><ref bean="dataSourceIbatis"/></property-->
    <property name="sqlMapClient"><ref bean="sqlMapClient"/></property>
    </bean>

    <bean id="operationDAO" class="it.axiosinformatica.webward.database.implem entations.OperationSqlMapDao">
    <!--property name="dataSource"><ref bean="dataSourceIbatis"/></property-->
    <property name="sqlMapClient"><ref bean="sqlMapClient"/></property>
    </bean>

    <bean id="palmDAO" class="it.axiosinformatica.webward.database.implem entations.PalmSqlMapDao">
    <!--property name="dataSource"><ref bean="dataSourceIbatis"/></property-->
    <property name="sqlMapClient"><ref bean="sqlMapClient"/></property>
    </bean>

    <bean id="palmWardDAO" class="it.axiosinformatica.webward.database.implem entations.PalmWardSqlMapDao">
    <!--property name="dataSource"><ref bean="dataSourceIbatis"/></property-->
    <property name="sqlMapClient"><ref bean="sqlMapClient"/></property>
    </bean>

    <bean id="patientBedDAO" class="it.axiosinformatica.webward.database.implem entations.PatientBedSqlMapDao">
    <!--property name="dataSource"><ref bean="dataSourceIbatis"/></property-->
    <property name="sqlMapClient"><ref bean="sqlMapClient"/></property>
    </bean>

    <bean id="patientDietDAO" class="it.axiosinformatica.webward.database.implem entations.PatientDietSqlMapDao">
    <!--property name="dataSource"><ref bean="dataSourceIbatis"/></property-->
    <property name="sqlMapClient"><ref bean="sqlMapClient"/></property>
    </bean>

    <bean id="patientDAO" class="it.axiosinformatica.webward.database.implem entations.PatientSqlMapDao">
    <!--property name="dataSource"><ref bean="dataSourceIbatis"/></property-->
    <property name="sqlMapClient"><ref bean="sqlMapClient"/></property>
    </bean>

    <bean id="plateDAO" class="it.axiosinformatica.webward.database.implem entations.PlateSqlMapDao">
    <!--property name="dataSource"><ref bean="dataSourceIbatis"/></property-->
    <property name="sqlMapClient"><ref bean="sqlMapClient"/></property>
    </bean>

    <bean id="profileDAO" class="it.axiosinformatica.webward.database.implem entations.ProfileSqlMapDao">
    <!--property name="dataSource"><ref bean="dataSourceIbatis"/></property-->
    <property name="sqlMapClient"><ref bean="sqlMapClient"/></property>
    </bean>

    <bean id="qualifyDAO" class="it.axiosinformatica.webward.database.implem entations.QualifySqlMapDao">
    <!--property name="dataSource"><ref bean="dataSourceIbatis"/></property-->
    <property name="sqlMapClient"><ref bean="sqlMapClient"/></property>
    </bean>

    <bean id="seasonDAO" class="it.axiosinformatica.webward.database.implem entations.SeasonSqlMapDao">
    <!--property name="dataSource"><ref bean="dataSourceIbatis"/></property-->
    <property name="sqlMapClient"><ref bean="sqlMapClient"/></property>
    </bean>

    <bean id="strongPlateDAO" class="it.axiosinformatica.webward.database.implem entations.StrongPlateSqlMapDao">
    <!--property name="dataSource"><ref bean="dataSourceIbatis"/></property-->
    <property name="sqlMapClient"><ref bean="sqlMapClient"/></property>
    </bean>

    <bean id="usageDAO" class="it.axiosinformatica.webward.database.implem entations.UsageSqlMapDao">
    <!--property name="dataSource"><ref bean="dataSourceIbatis"/></property-->
    <property name="sqlMapClient"><ref bean="sqlMapClient"/></property>
    </bean>

    <bean id="userParamDAO" class="it.axiosinformatica.webward.database.implem entations.UserParamSqlMapDao">
    <!--property name="dataSource"><ref bean="dataSourceIbatis"/></property-->
    <property name="sqlMapClient"><ref bean="sqlMapClient"/></property>
    </bean>

    <bean id="userDAO" class="it.axiosinformatica.webward.database.implem entations.UserSqlMapDao">
    <!--property name="dataSource"><ref bean="dataSourceIbatis"/></property-->
    <property name="sqlMapClient"><ref bean="sqlMapClient"/></property>
    </bean>

    <bean id="userTypeDAO" class="it.axiosinformatica.webward.database.implem entations.UserTypeSqlMapDao">
    <!--property name="dataSource"><ref bean="dataSourceIbatis"/></property-->
    <property name="sqlMapClient"><ref bean="sqlMapClient"/></property>
    </bean>

    <bean id="userWardDAO" class="it.axiosinformatica.webward.database.implem entations.UserWardSqlMapDao">
    <!--property name="dataSource"><ref bean="dataSourceIbatis"/></property-->
    <property name="sqlMapClient"><ref bean="sqlMapClient"/></property>
    </bean>

    <bean id="versionDAO" class="it.axiosinformatica.webward.database.implem entations.VersionSqlMapDao">
    <!--property name="dataSource"><ref bean="dataSourceIbatis"/></property-->
    <property name="sqlMapClient"><ref bean="sqlMapClient"/></property>
    </bean>

    <bean id="wardDietDAO" class="it.axiosinformatica.webward.database.implem entations.WardDietSqlMapDao">
    <!--property name="dataSource"><ref bean="dataSourceIbatis"/></property-->
    <property name="sqlMapClient"><ref bean="sqlMapClient"/></property>
    </bean>

    <bean id="wardMealDAO" class="it.axiosinformatica.webward.database.implem entations.WardMealSqlMapDao">
    <!--property name="dataSource"><ref bean="dataSourceIbatis"/></property-->
    <property name="sqlMapClient"><ref bean="sqlMapClient"/></property>
    </bean>

    <bean id="wardPatientUsageDAO" class="it.axiosinformatica.webward.database.implem entations.WardPatientUsageSqlMapDao">
    <!--property name="dataSource"><ref bean="dataSourceIbatis"/></property-->
    <property name="sqlMapClient"><ref bean="sqlMapClient"/></property>
    </bean>

    <bean id="wardPlateDAO" class="it.axiosinformatica.webward.database.implem entations.WardPlateSqlMapDao">
    <!--property name="dataSource"><ref bean="dataSourceIbatis"/></property-->
    <property name="sqlMapClient"><ref bean="sqlMapClient"/></property>
    </bean>

    <bean id="wardDAO" class="it.axiosinformatica.webward.database.implem entations.WardSqlMapDao">
    <!--property name="dataSource"><ref bean="dataSourceIbatis"/></property-->
    <property name="sqlMapClient"><ref bean="sqlMapClient"/></property>
    </bean>

    <!-- Add additional DAO definitions here -->



    <!-- Transaction template for Managers, from:
    http://blog.exis.com/colin/archives/...ons-spring-11/ -->
    <bean id="txProxyTemplate" abstract="true"
    class="org.springframework.transaction.interceptor .TransactionProxyFactoryBean">
    <property name="transactionManager"><ref bean="transactionManager"/></property>
    <property name="transactionAttributes">
    <props>
    <prop key="*">PROPAGATION_REQUIRED</prop>
    </props>
    </property>
    </bean>

    <bean id="accessOperationManager" parent="txProxyTemplate">
    <property name="target">
    <bean class="it.axiosinformatica.webward.manager.impl.Ac cessOperationManagerImpl">
    <property name="accessOperationDAO"><ref bean="accessOperationDAO"/></property>
    </bean>
    </property>
    <property name="transactionAttributes">
    <props>
    <prop key="*">PROPAGATION_REQUIRED</prop>
    </props>
    </property>
    </bean>

    <bean id="accessManager" parent="txProxyTemplate">
    <property name="target">
    <bean class="it.axiosinformatica.webward.manager.impl.Ac cessManagerImpl">
    <property name="accessDAO"><ref bean="accessDAO"/></property>
    </bean>
    </property>
    <property name="transactionAttributes">
    <props>
    <prop key="*">PROPAGATION_REQUIRED</prop>
    </props>
    </property>
    </bean>

    <bean id="baseParameterManager" parent="txProxyTemplate" >
    <property name="target">
    <bean class="it.axiosinformatica.webward.manager.impl.Ba seParameterManagerImpl">
    <property name="baseParameterDAO"><ref bean="baseParameterDAO"/></property>
    </bean>
    </property>
    <property name="transactionAttributes">
    <props>
    <prop key="*">PROPAGATION_REQUIRED</prop>
    </props>
    </property>
    </bean>

    <bean id="bedManager" parent="txProxyTemplate">
    <property name="target">
    <bean class="it.axiosinformatica.webward.manager.impl.Be dManagerImpl">
    <property name="bedDAO"><ref bean="bedDAO"/></property>
    <property name="patientManager"><ref bean="patientManager"/></property>
    </bean>
    </property>
    <property name="transactionAttributes">
    <props>
    <prop key="*">PROPAGATION_REQUIRED</prop>
    </props>
    </property>
    </bean>

    <bean id="courseManager" parent="txProxyTemplate">
    <property name="target">
    <bean class="it.axiosinformatica.webward.manager.impl.Co urseManagerImpl">
    <property name="courseDAO"><ref bean="courseDAO"/></property>
    </bean>
    </property>
    <property name="transactionAttributes">
    <props>
    <prop key="*">PROPAGATION_REQUIRED</prop>
    </props>
    </property>
    </bean>

    <bean id="dietComponentsManager" parent="txProxyTemplate">
    <property name="target">
    <bean class="it.axiosinformatica.webward.manager.impl.Di etComponentsManagerImpl">
    <property name="dietComponentsDAO"><ref bean="dietComponentsDAO"/></property>
    </bean>
    </property>
    <property name="transactionAttributes">
    <props>
    <prop key="*">PROPAGATION_REQUIRED</prop>
    </props>
    </property>
    </bean>

    <bean id="dietManager" parent="txProxyTemplate">
    <property name="target">
    <bean class="it.axiosinformatica.webward.manager.impl.Di etManagerImpl">
    <property name="dietDAO"><ref bean="dietDAO"/></property>
    </bean>
    </property>
    <property name="transactionAttributes">
    <props>
    <prop key="*">PROPAGATION_REQUIRED</prop>
    </props>
    </property>
    </bean>

    <bean id="extraKindManager" parent="txProxyTemplate">
    <property name="target">
    <bean class="it.axiosinformatica.webward.manager.impl.Ex traKindManagerImpl">
    <property name="extraKindDAO"><ref bean="extraKindDAO"/></property>
    </bean>
    </property>
    <property name="transactionAttributes">
    <props>
    <prop key="*">PROPAGATION_REQUIRED</prop>
    </props>
    </property>
    </bean>

    <bean id="fastManager" parent="txProxyTemplate">
    <property name="target">
    <bean class="it.axiosinformatica.webward.manager.impl.Fa stManagerImpl">
    <property name="fastDAO"><ref bean="fastDAO"/></property>
    </bean>
    </property>
    <property name="transactionAttributes">
    <props>
    <prop key="*">PROPAGATION_REQUIRED</prop>
    </props>
    </property>
    </bean>

    <bean id="functionOperationManager" parent="txProxyTemplate">
    <property name="target">
    <bean class="it.axiosinformatica.webward.manager.impl.Fu nctionOperationManagerImpl">
    <property name="functionOperationDAO"><ref bean="functionOperationDAO"/></property>
    </bean>
    </property>
    <property name="transactionAttributes">
    <props>
    <prop key="*">PROPAGATION_REQUIRED</prop>
    </props>
    </property>
    </bean>

    <bean id="functionManager" parent="txProxyTemplate">
    <property name="target">
    <bean class="it.axiosinformatica.webward.manager.impl.Fu nctionManagerImpl">
    <property name="functionDAO"><ref bean="functionDAO"/></property>
    </bean>
    </property>
    <property name="transactionAttributes">
    <props>
    <prop key="*">PROPAGATION_REQUIRED</prop>
    </props>
    </property>
    </bean>

    <bean id="hiddenParamManager" parent="txProxyTemplate">
    <property name="target">
    <bean class="it.axiosinformatica.webward.manager.impl.Hi ddenParamManagerImpl">
    <property name="hiddenParamDAO"><ref bean="hiddenParamDAO"/></property>
    </bean>
    </property>
    <property name="transactionAttributes">
    <props>
    <prop key="*">PROPAGATION_REQUIRED</prop>
    </props>
    </property>
    </bean>

    <bean id="languageManager" parent="txProxyTemplate">
    <property name="target">
    <bean class="it.axiosinformatica.webward.manager.impl.La nguageManagerImpl">
    <property name="languageDAO"><ref bean="languageDAO"/></property>
    </bean>
    </property>
    <property name="transactionAttributes">
    <props>
    <prop key="*">PROPAGATION_REQUIRED</prop>
    </props>
    </property>
    </bean>

    <bean id="mealManager" parent="txProxyTemplate">
    <property name="target">
    <bean class="it.axiosinformatica.webward.manager.impl.Me alManagerImpl">
    <property name="mealDAO"><ref bean="mealDAO"/></property>
    </bean>
    </property>
    <property name="transactionAttributes">
    <props>
    <prop key="*">PROPAGATION_REQUIRED</prop>
    </props>
    </property>
    </bean>

    <bean id="operationManager" parent="txProxyTemplate">
    <property name="target">
    <bean class="it.axiosinformatica.webward.manager.impl.Op erationManagerImpl">
    <property name="operationDAO"><ref bean="operationDAO"/></property>
    </bean>
    </property>
    <property name="transactionAttributes">
    <props>
    <prop key="*">PROPAGATION_REQUIRED</prop>
    </props>
    </property>
    </bean>

    <bean id="palmManager" parent="txProxyTemplate">
    <property name="target">
    <bean class="it.axiosinformatica.webward.manager.impl.Pa lmManagerImpl">
    <property name="palmDAO"><ref bean="palmDAO"/></property>
    </bean>
    </property>
    <property name="transactionAttributes">
    <props>
    <prop key="*">PROPAGATION_REQUIRED</prop>
    </props>
    </property>
    </bean>

    <bean id="palmWardManager" parent="txProxyTemplate">
    <property name="target">
    <bean class="it.axiosinformatica.webward.manager.impl.Pa lmWardManagerImpl">
    <property name="palmWardDAO"><ref bean="palmWardDAO"/></property>
    </bean>
    </property>
    <property name="transactionAttributes">
    <props>
    <prop key="*">PROPAGATION_REQUIRED</prop>
    </props>
    </property>
    </bean>

    <bean id="patientBedManager" parent="txProxyTemplate">
    <property name="target">
    <bean class="it.axiosinformatica.webward.manager.impl.Pa tientBedManagerImpl">
    <property name="patientBedDAO"><ref bean="patientBedDAO"/></property>
    </bean>
    </property>
    <property name="transactionAttributes">
    <props>
    <prop key="*">PROPAGATION_REQUIRED</prop>
    </props>
    </property>
    </bean>

    <bean id="patientDietManager" parent="txProxyTemplate">
    <property name="target">
    <bean class="it.axiosinformatica.webward.manager.impl.Pa tientDietManagerImpl">
    <property name="patientDietDAO"><ref bean="patientDietDAO"/></property>
    </bean>
    </property>
    <property name="transactionAttributes">
    <props>
    <prop key="*">PROPAGATION_REQUIRED</prop>
    </props>
    </property>
    </bean>

    <bean id="patientManager" parent="txProxyTemplate">
    <property name="target">
    <bean class="it.axiosinformatica.webward.manager.impl.Pa tientManagerImpl">
    <property name="patientDAO"><ref bean="patientDAO"/></property>
    <property name="patientDietManager"><ref bean="patientDietManager"/></property>
    <property name="fastManager"><ref bean="fastManager"/></property>
    </bean>
    </property>
    <property name="transactionAttributes">
    <props>
    <prop key="*">PROPAGATION_REQUIRED</prop>
    </props>
    </property>
    </bean>

    <bean id="plateManager" parent="txProxyTemplate">
    <property name="target">
    <bean class="it.axiosinformatica.webward.manager.impl.Pl ateManagerImpl">
    <property name="plateDAO"><ref bean="plateDAO"/></property>
    </bean>
    </property>

    </bean>

    <bean id="profileManager" parent="txProxyTemplate">
    <property name="target">
    <bean class="it.axiosinformatica.webward.manager.impl.Pr ofileManagerImpl">
    <property name="profileDAO"><ref bean="profileDAO"/></property>
    </bean>
    </property>
    <property name="transactionAttributes">
    <props>
    <prop key="*">PROPAGATION_REQUIRED</prop>
    </props>
    </property>
    </bean>

    <bean id="qualifyManager" parent="txProxyTemplate">
    <property name="target">
    <bean class="it.axiosinformatica.webward.manager.impl.Qu alifyManagerImpl">
    <property name="qualifyDAO"><ref bean="qualifyDAO"/></property>
    </bean>
    </property>

    </bean>

    <bean id="seasonManager" parent="txProxyTemplate">
    <property name="target">
    <bean class="it.axiosinformatica.webward.manager.impl.Se asonManagerImpl">
    <property name="seasonDAO"><ref bean="seasonDAO"/></property>
    </bean>
    </property>
    <property name="transactionAttributes">
    <props>
    <prop key="*">PROPAGATION_REQUIRED</prop>
    </props>
    </property>
    </bean>

    <bean id="strongPlateManager" parent="txProxyTemplate">
    <property name="target">
    <bean class="it.axiosinformatica.webward.manager.impl.St rongPlateManagerImpl">
    <property name="strongPlateDAO"><ref bean="strongPlateDAO"/></property>
    </bean>
    </property>

    </bean>

    <bean id="usageManager" parent="txProxyTemplate">
    <property name="target">
    <bean class="it.axiosinformatica.webward.manager.impl.Us ageManagerImpl">
    <property name="usageDAO"><ref bean="usageDAO"/></property>
    </bean>
    </property>
    <property name="transactionAttributes">
    <props>
    <prop key="*">PROPAGATION_REQUIRED</prop>
    </props>
    </property>
    </bean>

    <bean id="userParamManager" parent="txProxyTemplate">
    <property name="target">
    <bean class="it.axiosinformatica.webward.manager.impl.Us erParamManagerImpl">
    <property name="userParamDAO"><ref bean="userParamDAO"/></property>
    </bean>
    </property>
    <property name="transactionAttributes">
    <props>
    <prop key="*">PROPAGATION_REQUIRED</prop>
    </props>
    </property>
    </bean>

    <bean id="userManager" parent="txProxyTemplate">
    <property name="target">
    <bean class="it.axiosinformatica.webward.manager.impl.Us erManagerImpl">
    <property name="userDAO"><ref bean="userDAO"/></property>
    </bean>
    </property>

    </bean>

    <bean id="userTypeManager" parent="txProxyTemplate">
    <property name="target">
    <bean class="it.axiosinformatica.webward.manager.impl.Us erTypeManagerImpl">
    <property name="userTypeDAO"><ref bean="userTypeDAO"/></property>
    </bean>
    </property>
    <property name="transactionAttributes">
    <props>
    <prop key="*">PROPAGATION_REQUIRED</prop>
    </props>
    </property>
    </bean>

    <bean id="userWardManager" parent="txProxyTemplate">
    <property name="target">
    <bean class="it.axiosinformatica.webward.manager.impl.Us erWardManagerImpl">
    <property name="userWardDAO"><ref bean="userWardDAO"/></property>
    </bean>
    </property>
    <property name="transactionAttributes">
    <props>
    <prop key="*">PROPAGATION_REQUIRED</prop>
    </props>
    </property>
    </bean>

    <bean id="versionManager" parent="txProxyTemplate">
    <property name="target">
    <bean class="it.axiosinformatica.webward.manager.impl.Ve rsionManagerImpl">
    <property name="versionDAO"><ref bean="versionDAO"/></property>
    </bean>
    </property>
    <property name="transactionAttributes">
    <props>
    <prop key="*">PROPAGATION_REQUIRED</prop>
    </props>
    </property>
    </bean>

    <bean id="wardDietManager" parent="txProxyTemplate">
    <property name="target">
    <bean class="it.axiosinformatica.webward.manager.impl.Wa rdDietManagerImpl">
    <property name="wardDietDAO"><ref bean="wardDietDAO"/></property>
    </bean>
    </property>
    <property name="transactionAttributes">
    <props>
    <prop key="*">PROPAGATION_REQUIRED</prop>
    </props>
    </property>
    </bean>

    <bean id="wardMealManager" parent="txProxyTemplate">
    <property name="target">
    <bean class="it.axiosinformatica.webward.manager.impl.Wa rdMealManagerImpl">
    <property name="wardMealDAO"><ref bean="wardMealDAO"/></property>
    </bean>
    </property>
    <property name="transactionAttributes">
    <props>
    <prop key="*">PROPAGATION_REQUIRED</prop>
    </props>
    </property>
    </bean>

    <bean id="wardPatientUsageManager" parent="txProxyTemplate">
    <property name="target">
    <bean class="it.axiosinformatica.webward.manager.impl.Wa rdPatientUsageManagerImpl">
    <property name="wardPatientUsageDAO"><ref bean="wardPatientUsageDAO"/></property>
    </bean>
    </property>
    <property name="transactionAttributes">
    <props>
    <prop key="*">PROPAGATION_REQUIRED</prop>
    </props>
    </property>
    </bean>

    <bean id="wardPlateManager" parent="txProxyTemplate">
    <property name="target">
    <bean class="it.axiosinformatica.webward.manager.impl.Wa rdPlateManagerImpl">
    <property name="wardPlateDAO"><ref bean="wardPlateDAO"/></property>
    </bean>
    </property>
    <property name="transactionAttributes">
    <props>
    <prop key="*">PROPAGATION_REQUIRED</prop>
    </props>
    </property>
    </bean>

    <bean id="wardManager" parent="txProxyTemplate">
    <property name="target">
    <bean class="it.axiosinformatica.webward.manager.impl.Wa rdManagerImpl">
    <property name="wardDAO"><ref bean="wardDAO"/></property>
    </bean>
    </property>
    <property name="transactionAttributes">
    <props>
    <prop key="*">PROPAGATION_REQUIRED</prop>
    </props>
    </property>
    </bean>

    <bean id="lookupManager" parent="txProxyTemplate">
    <property name="target">
    <bean class="it.axiosinformatica.webward.manager.impl.Lo okupManagerImpl">
    <property name="accessManager"><ref bean="accessManager"/></property>
    <property name="accessOperationManager"><ref bean="accessOperationManager"/></property>
    <property name="baseParameterManager"><ref bean="baseParameterManager"/></property>
    <property name="bedManager"><ref bean="bedManager"/></property>
    <property name="courseManager"><ref bean="courseManager"/></property>
    <property name="dietComponentsManager"><ref bean="dietComponentsManager"/></property>
    <property name="dietManager"><ref bean="dietManager"/></property>
    <property name="extraKindManager"><ref bean="extraKindManager"/></property>
    <property name="fastManager"><ref bean="fastManager"/></property>
    <property name="functionManager"><ref bean="functionManager"/></property>
    <property name="functionOperationManager"><ref bean="functionOperationManager"/></property>
    <property name="hiddenParamManager"><ref bean="hiddenParamManager"/></property>
    <property name="languageManager"><ref bean="languageManager"/></property>
    <property name="mealManager"><ref bean="mealManager"/></property>
    <property name="operationManager"><ref bean="operationManager"/></property>
    <property name="palmManager"><ref bean="palmManager"/></property>
    <property name="palmWardManager"><ref bean="palmWardManager"/></property>
    <property name="patientBedManager"><ref bean="patientBedManager"/></property>
    <property name="patientDietManager"><ref bean="patientDietManager"/></property>
    <property name="patientManager"><ref bean="patientManager"/></property>
    <property name="plateManager"><ref bean="plateManager"/></property>
    <property name="profileManager"><ref bean="profileManager"/></property>
    <property name="qualifyManager"><ref bean="qualifyManager"/></property>
    <property name="seasonManager"><ref bean="seasonManager"/></property>
    <property name="strongPlateManager"><ref bean="strongPlateManager"/></property>
    <property name="usageManager"><ref bean="usageManager"/></property>
    <property name="userManager"><ref bean="userManager"/></property>
    <property name="userParamManager"><ref bean="userParamManager"/></property>
    <property name="userTypeManager"><ref bean="userTypeManager"/></property>
    <property name="userWardManager"><ref bean="userWardManager"/></property>
    <property name="versionManager"><ref bean="versionManager"/></property>
    <property name="wardDietManager"><ref bean="wardDietManager"/></property>
    <property name="wardManager"><ref bean="wardManager"/></property>
    <property name="wardMealManager"><ref bean="wardMealManager"/></property>
    <property name="wardPatientUsageManager"><ref bean="wardPatientUsageManager"/></property>
    <property name="wardPlateManager"><ref bean="wardPlateManager"/></property>
    </bean>
    </property>
    <property name="transactionAttributes">
    <props>
    <prop key="*">PROPAGATION_REQUIRED, -Exception, -DataAccessException</prop>
    </props>
    </property>
    </bean>
    </beans>


    The stackTrace:



    8-giu-2005 14.26.30 org.springframework.beans.factory.xml.XmlBeanDefin itionReader loadBeanDefinitions
    INFO: Loading XML bean definitions from class path resource [org/springframework/jdbc/support/sql-error-codes.xml]
    8-giu-2005 14.26.30 org.springframework.beans.factory.support.Abstract BeanFactory getBean
    INFO: Creating shared instance of singleton bean 'DB2'
    8-giu-2005 14.26.30 org.springframework.beans.factory.support.Abstract BeanFactory getBean
    INFO: Creating shared instance of singleton bean 'HSQL'
    8-giu-2005 14.26.30 org.springframework.beans.factory.support.Abstract BeanFactory getBean
    INFO: Creating shared instance of singleton bean 'MS-SQL'
    8-giu-2005 14.26.30 org.springframework.beans.factory.support.Abstract BeanFactory getBean
    INFO: Creating shared instance of singleton bean 'MySQL'
    8-giu-2005 14.26.30 org.springframework.beans.factory.support.Abstract BeanFactory getBean
    INFO: Creating shared instance of singleton bean 'Oracle'
    8-giu-2005 14.26.30 org.springframework.beans.factory.support.Abstract BeanFactory getBean
    INFO: Creating shared instance of singleton bean 'Informix'
    8-giu-2005 14.26.30 org.springframework.beans.factory.support.Abstract BeanFactory getBean
    INFO: Creating shared instance of singleton bean 'PostgreSQL'
    8-giu-2005 14.26.30 org.springframework.beans.factory.support.Abstract BeanFactory getBean
    INFO: Creating shared instance of singleton bean 'Sybase'
    8-giu-2005 14.26.30 org.springframework.jdbc.support.SQLErrorCodesFact ory <init>
    INFO: SQLErrorCodes loaded: [DB2, HSQL, MS-SQL, MySQL, Oracle, Informix, PostgreSQL, Sybase]
    8-giu-2005 14.26.30 org.apache.struts.action.RequestProcessor processException
    AVVERTENZA: Unhandled Exception thrown: class org.springframework.jdbc.UncategorizedSQLException
    8-giu-2005 14.26.30 org.apache.catalina.core.StandardWrapperValve invoke
    GRAVE: Servlet.service() for servlet actions threw exception
    org.springframework.jdbc.UncategorizedSQLException : SqlMapClient operation: encountered SQLException [
    --- The error occurred in ibatis/Fast.xml.
    --- The error occurred while preparing the mapped statement for execution.
    --- Check the Fast.insertFast.
    --- Check the parameter map.
    --- Cause: java.lang.NullPointerException]; nested exception is com.ibatis.common.jdbc.exception.NestedSQLExceptio n:
    --- The error occurred in ibatis/Fast.xml.
    --- The error occurred while preparing the mapped statement for execution.
    --- Check the Fast.insertFast.
    --- Check the parameter map.
    --- Cause: java.lang.NullPointerException
    com.ibatis.common.jdbc.exception.NestedSQLExceptio n:
    --- The error occurred in ibatis/Fast.xml.
    --- The error occurred while preparing the mapped statement for execution.
    --- Check the Fast.insertFast.
    --- Check the parameter map.
    --- Cause: java.lang.NullPointerException
    Caused by: java.lang.NullPointerException
    at com.ibatis.sqlmap.engine.mapping.statement.General Statement.executeUpdate(GeneralStatement.java:90)
    at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelega te.insert(SqlMapExecutorDelegate.java:442)
    at com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.in sert(SqlMapSessionImpl.java:85)
    at com.ibatis.sqlmap.engine.impl.SqlMapClientImpl.ins ert(SqlMapClientImpl.java:57)
    at org.springframework.orm.ibatis.SqlMapClientTemplat e$9.doInSqlMapClient(SqlMapClientTemplate.java:319 )
    at org.springframework.orm.ibatis.SqlMapClientTemplat e.execute(SqlMapClientTemplate.java:165)
    at org.springframework.orm.ibatis.SqlMapClientTemplat e.insert(SqlMapClientTemplate.java:317)
    at it.axiosinformatica.webward.database.implementatio ns.FastSqlMapDao.insertFast(FastSqlMapDao.java:50)
    at it.axiosinformatica.webward.manager.impl.FastManag erImpl.insertFast(FastManagerImpl.java:29)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at org.springframework.aop.support.AopUtils.invokeJoi npointUsingReflection(AopUtils.java:288)
    at org.springframework.aop.framework.ReflectiveMethod Invocation.invokeJoinpoint(ReflectiveMethodInvocat ion.java:155)
    at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :122)
    at org.springframework.transaction.interceptor.Transa ctionInterceptor.invoke(TransactionInterceptor.jav a:57)
    at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :144)
    at org.springframework.aop.framework.JdkDynamicAopPro xy.invoke(JdkDynamicAopProxy.java:174)
    at $Proxy42.insertFast(Unknown Source)
    at it.axiosinformatica.webward.web.actions.manageAdmi ssions.ManageAdmissionsNewPatientAction.doPerform( ManageAdmissionsNewPatientAction.java:203)
    at it.axiosinformatica.webward.web.actions.BaseSecure dAction.execute(BaseSecuredAction.java:45)
    at org.apache.struts.action.RequestProcessor.processA ctionPerform(RequestProcessor.java:421)
    at org.apache.struts.action.RequestProcessor.process( RequestProcessor.java:226)
    at org.apache.struts.action.ActionServlet.process(Act ionServlet.java:1164)
    at org.apache.struts.action.ActionServlet.doPost(Acti onServlet.java:415)
    at javax.servlet.http.HttpServlet.service(HttpServlet .java:709)
    at javax.servlet.http.HttpServlet.service(HttpServlet .java:802)
    at org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:252)
    at org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:173)
    at org.netbeans.modules.web.monitor.server.MonitorFil ter.doFilter(MonitorFilter.java:362)
    at org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:202)
    at org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:173)
    at org.apache.catalina.core.StandardWrapperValve.invo ke(StandardWrapperValve.java:214)
    at org.apache.catalina.core.StandardContextValve.invo ke(StandardContextValve.java:178)
    at org.apache.catalina.core.StandardHostValve.invoke( StandardHostValve.java:126)
    at org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:105)
    at org.apache.catalina.core.StandardEngineValve.invok e(StandardEngineValve.java:107)
    at org.apache.catalina.connector.CoyoteAdapter.servic e(CoyoteAdapter.java:148)
    at org.apache.coyote.http11.Http11Processor.process(H ttp11Processor.java:825)
    at org.apache.coyote.http11.Http11Protocol$Http11Conn ectionHandler.processConnection(Http11Protocol.jav a:738)
    at org.apache.tomcat.util.net.PoolTcpEndpoint.process Socket(PoolTcpEndpoint.java:526)
    at org.apache.tomcat.util.net.LeaderFollowerWorkerThr ead.runIt(LeaderFollowerWorkerThread.java:80)
    at org.apache.tomcat.util.threads.ThreadPool$ControlR unnable.run(ThreadPool.java:684)
    at java.lang.Thread.run(Thread.java:595)
    Caused by: java.lang.NullPointerException
    at it.axiosinformatica.webward.database.domain.Fast$$ BulkBeanByCGLIB$$38de3712.getPropertyValues(<gener ated>)
    at net.sf.cglib.beans.BulkBean.getPropertyValues(Bulk Bean.java:86)
    at com.ibatis.sqlmap.engine.accessplan.EnhancedProper tyAccessPlan.getProperties(EnhancedPropertyAccessP lan.java:37)
    at com.ibatis.sqlmap.engine.exchange.JavaBeanDataExch ange.getData(JavaBeanDataExchange.java:91)
    at com.ibatis.sqlmap.engine.mapping.parameter.BasicPa rameterMap.getParameterObjectValues(BasicParameter Map.java:132)
    at com.ibatis.sqlmap.engine.mapping.statement.General Statement.executeUpdate(GeneralStatement.java:67)
    ... 44 more

    Caused by:
    java.lang.NullPointerException
    at it.axiosinformatica.webward.database.domain.Fast$$ BulkBeanByCGLIB$$38de3712.getPropertyValues(<gener ated>)
    at net.sf.cglib.beans.BulkBean.getPropertyValues(Bulk Bean.java:86)
    at com.ibatis.sqlmap.engine.accessplan.EnhancedProper tyAccessPlan.getProperties(EnhancedPropertyAccessP lan.java:37)
    at com.ibatis.sqlmap.engine.exchange.JavaBeanDataExch ange.getData(JavaBeanDataExchange.java:91)
    at com.ibatis.sqlmap.engine.mapping.parameter.BasicPa rameterMap.getParameterObjectValues(BasicParameter Map.java:132)
    at com.ibatis.sqlmap.engine.mapping.statement.General Statement.executeUpdate(GeneralStatement.java:67)
    at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelega te.insert(SqlMapExecutorDelegate.java:442)
    at com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.in sert(SqlMapSessionImpl.java:85)
    at com.ibatis.sqlmap.engine.impl.SqlMapClientImpl.ins ert(SqlMapClientImpl.java:57)
    at org.springframework.orm.ibatis.SqlMapClientTemplat e$9.doInSqlMapClient(SqlMapClientTemplate.java:319 )
    at org.springframework.orm.ibatis.SqlMapClientTemplat e.execute(SqlMapClientTemplate.java:165)
    at org.springframework.orm.ibatis.SqlMapClientTemplat e.insert(SqlMapClientTemplate.java:317)
    at it.axiosinformatica.webward.database.implementatio ns.FastSqlMapDao.insertFast(FastSqlMapDao.java:50)
    at it.axiosinformatica.webward.manager.impl.FastManag erImpl.insertFast(FastManagerImpl.java:29)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at org.springframework.aop.support.AopUtils.invokeJoi npointUsingReflection(AopUtils.java:288)
    at org.springframework.aop.framework.ReflectiveMethod Invocation.invokeJoinpoint(ReflectiveMethodInvocat ion.java:155)
    at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :122)
    at org.springframework.transaction.interceptor.Transa ctionInterceptor.invoke(TransactionInterceptor.jav a:57)
    at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :144)
    at org.springframework.aop.framework.JdkDynamicAopPro xy.invoke(JdkDynamicAopProxy.java:174)
    at $Proxy42.insertFast(Unknown Source)
    at it.axiosinformatica.webward.web.actions.manageAdmi ssions.ManageAdmissionsNewPatientAction.doPerform( ManageAdmissionsNewPatientAction.java:203)
    at it.axiosinformatica.webward.web.actions.BaseSecure dAction.execute(BaseSecuredAction.java:45)
    at org.apache.struts.action.RequestProcessor.processA ctionPerform(RequestProcessor.java:421)
    at org.apache.struts.action.RequestProcessor.process( RequestProcessor.java:226)
    at org.apache.struts.action.ActionServlet.process(Act ionServlet.java:1164)
    at org.apache.struts.action.ActionServlet.doPost(Acti onServlet.java:415)
    at javax.servlet.http.HttpServlet.service(HttpServlet .java:709)
    at javax.servlet.http.HttpServlet.service(HttpServlet .java:802)
    at org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:252)
    at org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:173)
    at org.netbeans.modules.web.monitor.server.MonitorFil ter.doFilter(MonitorFilter.java:362)
    at org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:202)
    at org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:173)
    at org.apache.catalina.core.StandardWrapperValve.invo ke(StandardWrapperValve.java:214)
    at org.apache.catalina.core.StandardContextValve.invo ke(StandardContextValve.java:178)
    at org.apache.catalina.core.StandardHostValve.invoke( StandardHostValve.java:126)
    at org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:105)
    at org.apache.catalina.core.StandardEngineValve.invok e(StandardEngineValve.java:107)
    at org.apache.catalina.connector.CoyoteAdapter.servic e(CoyoteAdapter.java:148)
    at org.apache.coyote.http11.Http11Processor.process(H ttp11Processor.java:825)
    at org.apache.coyote.http11.Http11Protocol$Http11Conn ectionHandler.processConnection(Http11Protocol.jav a:738)
    at org.apache.tomcat.util.net.PoolTcpEndpoint.process Socket(PoolTcpEndpoint.java:526)
    at org.apache.tomcat.util.net.LeaderFollowerWorkerThr ead.runIt(LeaderFollowerWorkerThread.java:80)
    at org.apache.tomcat.util.threads.ThreadPool$ControlR unnable.run(ThreadPool.java:684)
    at java.lang.Thread.run(Thread.java:595)



    Ah, the NullPointerException is correct, i've simulate an error in the last table!

    Any idea?

  2. #2
    Join Date
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    1,104

    Default

    It is correct?
    Why not remove the manager layer, which is one-to-one with the DAOs. You are wrapping DAOs in a manager transactional proxy, and then wrapping that in another transactional proxy at the lookupManager level - you should probably only define one transactional service layer.

    You could just insert your DAOs into the lookupManager, or just remove the transaction proxies from the manager level.

  3. #3
    Join Date
    Jun 2005
    Location
    Italy
    Posts
    16

    Default

    Quote Originally Posted by katentim
    It is correct?
    Why not remove the manager layer, which is one-to-one with the DAOs. You are wrapping DAOs in a manager transactional proxy, and then wrapping that in another transactional proxy at the lookupManager level - you should probably only define one transactional service layer.

    You could just insert your DAOs into the lookupManager, or just remove the transaction proxies from the manager level.

    Many thanks for reply katentim!


    OK!
    Following your suggestion, i've created a veriy simple, stupid example....but still not work!
    I've moved my DAO into dao manager layer, but the transaction don't mark my tables!

    I'll post the entire example, you can test it! Where i mistake?


    //////////////////////////////////// The sql (very, very very simple)//////////////////////////////////////////////


    create table table_A (
    description Varchar(100) not null
    );

    create table table_B (
    description Varchar(100) not null
    );




    ////////////////////////////////////// The Ibatis 2.1.0 sqlmap (restrict to test) /////////////////////////////////////////

    <sqlMapConfig>
    <settings enhancementEnabled="true"
    lazyLoadingEnabled="true"
    useStatementNamespaces="true"/>

    <sqlMap resource="ibatis/table-A.xml"/>
    <sqlMap resource="ibatis/table-B.xml"/>

    </sqlMapConfig>


    ////////////////////////////////////// The Table A & Table B Mapping (stupid) ////////////////////////////////////

    ----TABLE A

    <sqlMap namespace="Table-A">
    <typeAlias alias="tableA" type="testSpring.database.domain.TableA"/>

    <resultMap id="get-table-result" class="tableA">
    <result property="description" column="DESCRIPTION" />
    </resultMap>

    <insert id="insertTableA" parameterClass="tableA" >
    <![CDATA[
    INSERT INTO TABLE_A (Description) VALUES (#description#) ]]>
    </insert>

    </sqlMap>

    ----TABLE B

    <sqlMap namespace="Table-B">
    <typeAlias alias="tableB" type="testSpring.database.domain.TableB"/>

    <resultMap id="get-table-result" class="tableB">
    <result property="description" column="DESCRIPTION" />
    </resultMap>

    <insert id="insertTableB" parameterClass="tableB" >
    <![CDATA[
    INSERT INTO Table_B (Description) VALUES (#description#) ]]>
    </insert>

    </sqlMap>


    ////////////////////////////////////// For this case i use struts, you can use anything ////////////////

    -----StrustConfig.xml

    <struts-config>
    <!-- ========== Form Bean Definitions =================================== -->
    <form-beans>
    <form-bean name="emptyForm" type="org.apache.struts.validator.DynaValidatorFor m">
    </form-bean>
    </form-beans>
    <!-- ========== Global Forward Definitions =================================== -->
    <global-forwards>
    <forward name="home" path="/home.do"/>
    <forward name="main" path="/main.do"/>
    </global-forwards>
    <!-- ========== Action Mapping Definitions =================================== -->
    <action-mappings>
    <action path="/home" validate="false" scope="request" type="org.apache.struts.actions.ForwardAction" parameter="/WEB-INF/pages/main.jsp"/>
    <action path="/main" scope="request" type="testSpring.web.MainAction" name="emptyForm" validate="false" input="/WEB-INF/pages/main.jsp" >
    <forward name="success" path="/home.do"/>
    </action>
    </action-mappings>
    </struts-config>



    ////////////////////////////////////Ok??? Now, the ApplicationContext /////////////////////////////////////////

    <beans>
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
    <property name="driverClassName">
    <value>org.firebirdsql.jdbc.FBDriver</value>
    </property>
    <property name="url">
    <value>jdbc:firebirdsql://127.0.0.1:3050//home/luiber/testSpring/db/springTest.fdb</value>
    </property>
    <property name="username">
    <value>sysdba</value>
    </property>
    <property name="password">
    <value>masterkey</value>
    </property>
    </bean>

    <!-- Transaction manager for iBATIS DAOs -->
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSou rceTransactionManager">
    <property name="dataSource"><ref bean="dataSource"/></property>
    </bean>

    <!-- SqlMap setup for iBATIS Database Layer -->
    <bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClient FactoryBean" >
    <property name="configLocation">
    <value>classpath:/SqlMapConfig.xml</value>
    </property>
    <property name="dataSource"><ref bean="dataSource"/></property>
    </bean>


    <bean id="tableADao" class="testSpring.database.impl.TableADaoImpl">
    <property name="sqlMapClient"><ref bean="sqlMapClient"/></property>
    </bean>

    <bean id="tableBDao" class="testSpring.database.impl.TableBDaoImpl">
    <property name="sqlMapClient"><ref bean="sqlMapClient"/></property>
    </bean>

    <!-- Transaction template for Managers, from:
    http://blog.exis.com/colin/archives/...ons-spring-11/ -->
    <bean id="txProxyTemplate" abstract="true"
    class="org.springframework.transaction.interceptor .TransactionProxyFactoryBean">
    <property name="transactionManager"><ref bean="transactionManager"/></property>
    <!--Note: i'ts hide-->
    <!--property name="transactionAttributes">
    <props>
    <prop key="*">PROPAGATION_REQUIRED</prop>
    </props>
    </property-->
    </bean>

    <bean id="managerLayer" parent="txProxyTemplate">
    <property name="target">
    <bean class="testSpring.database.managerLayer.impl.Manag erLayerImpl">
    <property name="tableBDao"><ref bean="tableBDao"/></property>
    <property name="tableADao"><ref bean="tableADao"/></property>
    </bean>
    </property>
    <property name="transactionAttributes">
    <props>
    <prop key="*">PROPAGATION_REQUIRED, -DataAccessException</prop>
    </props>
    </property>
    </bean>
    </beans>



    //////////////////////////////////Now, starting the POJO & SQLMAP//////////////////////////////////////////

    ----------POJO

    public class TableA implements Serializable {

    private String description;


    /** default constructor */
    public TableA() {
    }


    public String getDescription() {
    return this.description;
    }

    public void setDescription(String d) {
    this.description = d;
    }

    }


    public class TableB implements Serializable {

    private String description;


    /** default constructor */
    public TableB() {
    }

    public String getDescription() {
    return this.description;
    }

    public void setDescription(String d) {
    this.description = d;
    }

    }




    ---------------------SQLMAP IMPLEMENATATION (Table A & table B Dao are simple interface)

    public class TableADaoImpl extends SqlMapClientDaoSupport implements TableADao {
    public Integer insert(testSpring.database.domain.TableA obj) throws org.springframework.dao.DataAccessException {
    return (Integer) getSqlMapClientTemplate().insert("Table-A.insertTableA", obj);
    }
    }


    public class TableBDaoImpl extends SqlMapClientDaoSupport implements TableBDao {

    public Integer insert(testSpring.database.domain.TableB obj) throws org.springframework.dao.DataAccessException {
    return (Integer) getSqlMapClientTemplate().insert("Table-B.insertTableB", obj);
    }

    }



    //////////////////////////////////////////////Repeat: it's stupid test, but is valid! Now, The managerLayer /////////////////////////////////////

    public class ManagerLayerImpl implements ManagerLayer{

    private TableADao tam;
    private TableBDao tbm;

    public void setTableADao(TableADao mgr){
    this.tam = mgr;
    }

    public void setTableBDao(TableBDao mgr){
    this.tbm = mgr;
    }

    public TableADao getTableADao(){
    return this.tam;
    }

    public TableBDao getTableBDao(){
    return this.tbm;
    }

    }





    ///////////////////////// At the end, iI'll post the Action ///////////////////////////


    ---BASE ACTION (where i load the applicationContext)

    public abstract class BaseAction extends Action {

    //load applicationContext
    static ApplicationContext ctx = null;
    static {
    String[] paths = {"applicationContext.xml"};
    ctx = new ClassPathXmlApplicationContext(paths);
    try {
    } catch (Exception e) {
    throw new RuntimeException("There was an error initializing BaseAction. Cause: " + e);
    }
    }

    //return required Bean
    protected Object getBean(String beanName) {
    return ctx.getBean(beanName);
    }


    public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
    throws Exception {

    return doPerform(mapping, form, request, response);
    }

    public abstract ActionForward doPerform(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
    throws Exception;
    }




    -----And the main action (where i call the test)



    public class MainAction extends BaseAction {

    private ManagerLayer manager = (ManagerLayer) getBean("managerLayer");

    public ActionForward doPerform(ActionMapping mapping, ActionForm form,
    HttpServletRequest req, HttpServletResponse res) throws Exception{

    DynaActionForm theForm = (DynaActionForm) form;

    TableA a = new TableA();
    a.setDescription("TestRecord");
    manager.getTableADao().insert(a);

    TableB b = new TableB();
    b.setDescription(null); // SIMULATE ERROR
    manager.getTableBDao().insert(b);

    return mapping.findForward("success");

    }

    }



    ---So, if you run this test, the tableA record will be inserted and is not rolled back (although tableB error)



    ----Anyone have any idea???????????????????


    I think that is a stupid error (i'm a newbie in Spring), but i cannot resolve this!

    Help please!

  4. #4
    Join Date
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    1,104

    Default

    Change
    Code:
    TableA a = new TableA&#40;&#41;;
    a.setDescription&#40;"TestRecord"&#41;;
    manager.getTableADao&#40;&#41;.insert&#40;a&#41;;
    
    TableB b = new TableB&#40;&#41;;
    b.setDescription&#40;null&#41;; // SIMULATE ERROR
    manager.getTableBDao&#40;&#41;.insert&#40;b&#41;;
    to:
    Code:
    TableA a = new TableA&#40;&#41;;
    a.setDescription&#40;"TestRecord"&#41;;
    
    TableB b = new TableB&#40;&#41;;
    b.setDescription&#40;null&#41;; // SIMULATE ERROR
    manager.insert&#40;a,b&#41;;
    You must remove the getTableDAO methods, as this bypasses the transactional proxy. You must also do the inserts as a single method call to the managerLayer.

    The line:
    Code:
     <prop key="*">PROPAGATION_REQUIRED</prop>
    means that each method of the proxy (managerLayer) will occur in a transaction.

    To get code like:
    Code:
    manager.getTableADao&#40;&#41;.insert&#40;a&#41;;
    manager.getTableBDao&#40;&#41;.insert&#40;b&#41;;
    to be transactional, you can look at Spring's programmatic transactions with TransactionTemplate.

  5. #5
    Join Date
    Jun 2005
    Location
    Italy
    Posts
    16

    Default

    Quote Originally Posted by katentim
    Change
    Code:
    TableA a = new TableA&#40;&#41;;
    a.setDescription&#40;"TestRecord"&#41;;
    manager.getTableADao&#40;&#41;.insert&#40;a&#41;;
    
    TableB b = new TableB&#40;&#41;;
    b.setDescription&#40;null&#41;; // SIMULATE ERROR
    manager.getTableBDao&#40;&#41;.insert&#40;b&#41;;
    to:
    Code:
    TableA a = new TableA&#40;&#41;;
    a.setDescription&#40;"TestRecord"&#41;;
    
    TableB b = new TableB&#40;&#41;;
    b.setDescription&#40;null&#41;; // SIMULATE ERROR
    manager.insert&#40;a,b&#41;;
    You must remove the getTableDAO methods, as this bypasses the transactional proxy. You must also do the inserts as a single method call to the managerLayer.

    The line:
    Code:
     <prop key="*">PROPAGATION_REQUIRED</prop>
    means that each method of the proxy (managerLayer) will occur in a transaction.

    To get code like:
    Code:
    manager.getTableADao&#40;&#41;.insert&#40;a&#41;;
    manager.getTableBDao&#40;&#41;.insert&#40;b&#41;;
    to be transactional, you can look at Spring's programmatic transactions with TransactionTemplate.


    IT WORKS!!!!!! You are Fantastic!!!!

    Thanks a lot!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

  6. #6
    Join Date
    Jun 2005
    Location
    Italy
    Posts
    16

    Default

    To get code like:
    Code:
    manager.getTableADao().insert(a);
    manager.getTableBDao().insert(b);

    to be transactional, you can look at Spring's programmatic transactions with TransactionTemplate.


    I've follow this idea, and i've modify my applicationContext to work transactionally.

    I've read your link and this article http://speedo.objectweb.org/doc/dev_spring.html



    So, i've create this:




    <beans>
    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverM anagerDataSource">
    <property name="driverClassName">
    <value>org.firebirdsql.jdbc.FBDriver</value>
    </property>
    <property name="url">
    <value>jdbc:firebirdsql://127.0.0.1:3050//home/luiber/testSpring/db/springTest.fdb</value>
    </property>
    <property name="username">
    <value>sysdba</value>
    </property>
    <property name="password">
    <value>masterkey</value>
    </property>
    </bean>

    <!-- Transaction manager for iBATIS DAOs -->
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSou rceTransactionManager">
    <property name="dataSource"><ref bean="dataSource"/></property>
    </bean>

    <!-- SqlMap setup for iBATIS Database Layer -->
    <bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClient FactoryBean" >
    <property name="configLocation">
    <value>classpath:/SqlMapConfig.xml</value>
    </property>
    <property name="dataSource"><ref bean="dataSource"/></property>
    </bean>


    <bean id="tableADao" class="testSpring.database.impl.TableADaoImpl">
    <property name="sqlMapClient"><ref bean="sqlMapClient"/></property>
    </bean>

    <bean id="tableBDao" class="testSpring.database.impl.TableBDaoImpl">
    <property name="sqlMapClient"><ref bean="sqlMapClient"/></property>
    </bean>

    <!-- Transaction template for Managers, from:
    http://blog.exis.com/colin/archives/...ons-spring-11/ -->
    <!--bean id="txProxyTemplate" abstract="true"
    class="org.springframework.transaction.interceptor .TransactionProxyFactoryBean">
    <property name="transactionManager"><ref bean="transactionManager"/></property>
    <property name="transactionAttributes">
    <props>
    <prop key="*">PROPAGATION_REQUIRED, -DataAccessException, -Exception</prop>
    </props>
    </property>
    </bean-->

    <bean id="matchAllWithPropReq"
    class="org.springframework.transaction.interceptor .MatchAlwaysTransactionAttributeSource">
    <property name="transactionAttribute"><value>PROPAGATION_REQ UIRED</value></property>
    </bean>
    <bean id="transactionInterceptor"
    class="org.springframework.transaction.interceptor .TransactionInterceptor" >
    <property name="transactionManager"><ref bean="transactionManager"/></property>
    <property name="transactionAttributeSource"><ref bean="matchAllWithPropReq"/></property>
    </bean>

    <!-- One BeanNameAutoProxyCreator handles all beans where we want all methods to use
    PROPAGATION_REQUIRED -->
    <bean id="autoProxyCreator"
    class="org.springframework.aop.framework.autoproxy .BeanNameAutoProxyCreator" >
    <property name="interceptorNames">
    <list>
    <value>transactionInterceptor</value>
    </list>
    </property>
    <property name="beanNames">
    <list>
    <value>managerLayer</value>
    <value>*Dao</value>
    </list>
    </property>
    </bean>


    <bean id="managerLayer" class="testSpring.database.managerLayer.impl.Manag erLayerImpl" >

    <property name="tableBDao"><ref bean="tableBDao"/></property>
    <property name="tableADao"><ref bean="tableADao"/></property>

    </bean>


    <!--bean id="managerLayer" parent="txProxyTemplate">
    <property name="target">
    <bean class="testSpring.database.managerLayer.impl.Manag erLayerImpl">
    <property name="tableBDao"><ref bean="tableBDao"/></property>
    <property name="tableADao"><ref bean="tableADao"/></property>
    </bean>
    </property>
    </bean-->
    </beans>



    -----But, the transactions are separated and the rollback not happens!!!


    I want to use the "beautiful" code:

    manager.getTableADao().insert(a);
    manager.getTableBDao().insert(b);

    But i have this problem.

    Any Idea?

    Thanks for reply!

  7. #7
    Join Date
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    1,104

    Default

    To get code like:
    Code:
    manager.getTableADao().insert(a);
    manager.getTableBDao().insert(b);

    to be transactional, you can look at Spring's programmatic transactions with TransactionTemplate.
    This transaction handling in this code is programmatic (are you sure you want programmatic transaction demarcation?), so you can remove the transactional proxies from your app. context.

    You'll need the following:
    Code:
    	<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    		<property name="dataSource"><ref bean="dataSource"/></property>
    	</bean>
    
    	<bean id="transactionTemplate" class="org.springframework.transaction.support.TransactionTemplate">
    		<property name="transactionManager"><ref bean="transactionManager"/></property>
    	</bean>
    
    	<bean id="managerLayer" class="testSpring.database.managerLayer.impl.ManagerLayerImpl" >
    		<property name="transactionTemplate><ref local="transactionTemplate"/></property>
    		<property name="tableBDao"><ref bean="tableBDao"/></property>
    		<property name="tableADao"><ref bean="tableADao"/></property>
    	</bean>


    Code:
    	DefaultTransactionDefinition def = new DefaultTransactionDefinition&#40;&#41;;
    	def.setPropagationBehavior&#40;TransactionDefinition.PROPAGATION_REQUIRED&#41;;
    
    	transactionTemplate.execute&#40;new TransactionCallbackWithoutResult&#40;&#41; &#123;
    	    protected void doInTransactionWithoutResult&#40;TransactionStatus status&#41; &#123;
    			manager.getTableADao&#40;&#41;.insert&#40;a&#41;;
    			manager.getTableBDao&#40;&#41;.insert&#40;b&#41;;
    	    &#125;
    	&#125;&#41;;

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: May 16th, 2005, 07:04 AM
  4. Replies: 3
    Last Post: Nov 19th, 2004, 07:16 PM
  5. Transaction pb Hibernate/MySQL
    By syluser in forum Data
    Replies: 2
    Last Post: Aug 28th, 2004, 02:40 PM

Posting Permissions

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