0

I use JTATransactionManager to manage Transactions. One piece of code that I want to wrap with Spring's @Transactional annotation has 2 database calls - one using Hibernate SessionFactory and another a plain JDBC. Both use the same dataSource. Hence, I expect both to be bound by the same Transaction.

But it does not look like one Transaction is used. Instead each opens its own Transaction. What could be the reason for this. ? How do I make sure to use a single Transaction to bind both these operations. ?

I can provide configuration and code if needed.

Anand Hemmige
  • 3,593
  • 6
  • 21
  • 31

1 Answers1

0

Make sure in both of your database calls, you use propagation as Propagation.NESTED as

  @Transactional(propagation=Propagation.NESTED) 

and in the wrapper method, you mention Propagation.REQUIRED orPropagation.REQUIRED_NEW` as

  @Transactional(propagation=Propagation.REQUIRED)

or

  @Transactional(propagation=Propagation.REQUIRED_NEW)

By doing this, you mention that both DB calls will inherit the transaction boundary of the wrapper method.

Yogendra Singh
  • 33,927
  • 6
  • 63
  • 73
  • I did not work for me. Basically, I annotated the wrapper method in my service with `@Transactional(propagation=Propagation.REQUIRED)` and annotated the 2 database calling methods in the same service with `@Transactional(propagation=Propagation.NESTED) `. So the wrapper method calls these 2 methods int he same service. Is this what you suggested ..? – Anand Hemmige Nov 13 '12 at 19:35
  • @AnandHemmige: Yes. Also I think you need to configure spring to use annotation base transaction as ``. Use your transaction manager name in the statement. – Yogendra Singh Nov 13 '12 at 19:47