Announcement Announcement Module
Collapse
No announcement yet.
Two database connections at the same time Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Two database connections at the same time

    Hello.

    What would be the preferred way to connect to two databases at the same time using hibernate, spring and declarative transactions?

    We are trying to migrate data from source database to target database and manually created two Spring contexts with each using its own database.

    We are using the "DataSourceTransactionManager" to manage the declarative transaction in each Spring context created. When we manually start both Spring contexts and start both transactions with its own transaction manager, somehow both transactions become synchronized and need to be nested. If they aren't nested an Exception occurs (java.lang.IllegalStateException: Cannot deactivate transaction synchronization - not active). Why did both transactions synchronize? What would be the preferred way to manage the transactions in such a case?

    Any suggestion appreciated.

    Thanks, Tomaz

  • #2
    if i'm not mistaken
    using 2 database must use a JTATransactionManager

    Comment


    • #3
      Originally posted by isyak View Post
      if i'm not mistaken
      using 2 database must use a JTATransactionManager
      Thanks.. I'm aware of this but we don't want to use JTATransactionManager - it's too heavyweight. Is there another way?

      Comment


      • #4
        Originally posted by quikee View Post
        I'm aware of this but we don't want to use JTATransactionManager - it's too heavyweight. Is there another way?
        No (not that I'm aware of). Why is it too heavy-weighted? You don't need to use a full-blown JEE server but can go with a lightweight solution like Jencks, JOTM or Atomikos. Of course there is a overhead from using JTA and it needs effort to set it up, but that's necessary when you need to synchronize the two transactions.

        Joerg

        Comment


        • #5
          You should be able to have 2 separate transaction managers for 2 databases. Can you post your datasource/transaction manager/transaction config please?

          Comment

          Working...
          X