Announcement Announcement Module
No announcement yet.
Independent data sourcess and transactions Page Title Module
Move Remove Collapse
Conversation Detail Module
  • 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:

    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.orm.hibernate.HibernateTransactionManager.doBegin(
    	at org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(
    	at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(
    	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(
    	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.