Frage

i'm facing a problem i really dunno how to catch the cat tail (if you hollow me the joke :o))

i have a webapp in war, deploy in tomcat. the war contains 4 Jars. 4 jars have 4 applicationContext, with 4 entityManager, and 4 TransactionManager.

declare like this (change the number 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" />

the context is load like this :

my problem i discover that when i'm using a BO of 3, the transaction is open with the datasource of 2.

moreover, if i do a persist i have the message :

AbstractSaveEventListener - delaying identity-insert due to no transaction in progress

BUT if i launch the jar 1 alone (for example), everything is working perfectly.

thanks a lot for your enlightement.

War es hilfreich?

Lösung

Let me guess:

in your servlet-context.xml, do you import the contexts? e.g.:

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

etc.

If you do, all bean definitions are copied from the imported context into the root context, which means that you have four different <tx:annotation-driven /> declarations, with different transaction managers. Probably the last one wins.

Possible solutions: Either use Qualifiers or use the XML style of transaction declaration.

What I'd do is probably to introduce a custom @Transactional annotation per context:

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

Now annotate all methods in jar 1 with @Transactional1, in jar 2 with @Transactional2 etc. This mechanism is documented in the Section 10.5.6.3 Custom shortcut annotations

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top