2011-05-17 61 views
2

我现在面临一个问题,我真的不知道如何捕捉到猫尾巴的交易(如果你镂空我的笑话:O))事务管理不承担

我在战争中的Web应用程序,部署tomcat的。战争包含4个罐子。 4个jar包含4个applicationContext,4个entityManager和4个TransactionManager。

声明是这样的(换号1 ..):

 <bean id="entityManagerFactory1" 
    class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" 
    p:dataSource-ref="dataSource1" 
    p:persistence-unit-name="com.xxxxxx.domain"  > 

    <property name="jpaVendorAdapter"> 
     <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" 
     p:databasePlatform="${ds1.dbdialect}" p:generate-ddl="false" 
      p:showSql="${ds1.showsql}" /> 
    </property> 
    <property name="loadTimeWeaver"> 
     <bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver" /> 
    </property> 
</bean> 

    <bean id="transactionManager1" class="org.springframework.orm.jpa.JpaTransactionManager" 
    p:entityManagerFactory-ref="entityManagerFactory1"> 
    depends-on="entityManagerFactory1" name="transactionManager1"/> 


    <tx:annotation-driven transaction-manager="transactionManager1" /> 

上下文是负载这样的:

我的问题,我发现,当我使用的是BO 3,交易是打开的数据源2.

此外,如果我坚持我有消息:

AbstractSaveEventListener - 由于没有正在处理的事务而延迟标识插入

但是,如果我单独启动jar 1(例如),那么所有内容都可以正常工作。

非常感谢您的启发。

回答

2

让我猜:

在您的servlet-context.xml中,您是否导入上下文?例如: -

<import location="classpath:context1.xml" /> 
<import location="classpath:context2.xml" /> 

如果你这样做,所有的bean定义是从进口方面到根上下文,这意味着你有四个不同的<tx:annotation-driven />声明,与不同的事务管理复制。可能是最后一个胜利。

可能的解决方案:use Qualifiersuse the XML style of transaction declaration

我会做什么可能是引进每次上下文定制@Transactional注释:

@Transactional("tx1") 
@Inherited 
@Retention(RetentionPolicy.RUNTIME) 
@Target({ElementType.TYPE,ElementType.METHOD}) 
public @interface Transactional1 {} 

现在注释在罐子1中的所有方法与@Transactional1,在罐子2 @Transactional2等这种机制在记录部分10.5.6.3 Custom shortcut annotations

+0

非常感谢!我使用XML风格的事务声明,因为我的spring版本有点旧。 – 2011-05-19 09:11:35