views:

275

answers:

2

Hi all,

To avoid XA overhead I prefixed some table names from project A and rolled it out to be inside the same mysql database as project B so I can use the same connection - and hope to get full atomicity etc.

Project A and B though have very different session factory configs. I have a HibernateTransactionManager configured for project B whereas A simply uses TransactionSynchronizationManager.hasResource(sessionFactoryA) OSiV style code to join with the transaction.

Does this work conceptually? I just tried a breakpoint in A, then wait, then continue and the timeout causes B to rollback, but A still commits!!?

What gives? Thanks for any help.

+1  A: 

Even though both sets of entities reside in the same database, you've still configured Spring with two different transaction managers. As a result, you end up with overlapping, but completely separate transactions, with different database connections being used for each.

In order to get transactions working properly, you need to use one transaction manager, and send all transactional operations through that.

skaffman
thanks - I realised that providing the same dataSource does not mean the same connection is used. One transaction would be fine (A piggybacks around B's tx methods using aop) but HibernateTransactionManger only manages one factory, and hence one dataSource... So I would have to go the whole hog - and have jta transaction manager and XA mysql drivers too???
adam
Either use JTA, or merge your session factories into one configuration.
skaffman
+1  A: 

With your current setup, I'm afraid you'll need a JtaTransactionManager (section 12.2.8. Transaction management strategies). If you want to avoid using XA, you need to use a single and unique connection.

Pascal Thivent