Announcement Announcement Module
Collapse
No announcement yet.
Independent data sourcess and transactions Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Independent data sourcess and transactions

    I'm trying to use two independent HibernateTransactionManager objects in the same thread. Each has its own Hibernate SessionFactory and DataSource, which are also independent.

    I have two business service objects, each created from a TransactionProxyFactoryBean. The first factory bean references the first HibernateTransactionManager. The second one references the second HibernateTransactionManager.

    Unfortunately, I'm running into an error when a method in one of the business service objects tries to call a method in the other. The exception looks like this:

    Code:
    org.springframework.transaction.CannotCreateTransactionException: Could not create Hibernate transaction; nested exception is java.lang.IllegalStateException: Already value [org.springframework.jdbc.datasource.ConnectionHolder@dfe303] for key [org.apache.commons.dbcp.BasicDataSource@345b43] bound to thread [main]
    java.lang.IllegalStateException: Already value [org.springframework.jdbc.datasource.ConnectionHolder@dfe303] for key [org.apache.commons.dbcp.BasicDataSource@345b43] bound to thread [main]
    	at org.springframework.transaction.support.TransactionSynchronizationManager.bindResource(TransactionSynchronizationManager.java:137)
    	at org.springframework.orm.hibernate.HibernateTransactionManager.doBegin(HibernateTransactionManager.java:415)
    	at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:269)
    	at org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:201)
    	at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:49)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:138)
    	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:152)
    	at $Proxy10.loadAll(Unknown Source)
    ...
    It seems like the transaction proxy doesn't realize that there are two separate SessionFactory/DataSource objects. Should this work? Is it possible to have one transaction proxy nest a call to another if the two manage transactions for different data sources?

  • #2
    Never mind. The problem was that I was initializing the second set of objects while a transaction was active. Apparently that doesn't work too well. If I suspend transactions while the second set is being initialized, it seems to be fine.

    Comment

    Working...
    X