0

I have bean using BMT. Another bean using BMT is injected into the first. Now when the first one calls a method of the second one, suddenly the transaction is closed. In my code I narrowed it down to exactly the point before the method call and inside of it.

Here is the trace:

2018-11-23 12:15:32,275 +0100 [TRACE] [com.arjuna.ats.jta] (default task-18) TransactionImple.getStatus: javax.transaction.Status.STATUS_ACTIVE

2018-11-23 12:15:32,276 +0100 [TRACE] [com.arjuna.ats.jta] (default task-18) TransactionImpleManager.suspend

2018-11-23 12:15:32,277 +0100 [TRACE] [com.arjuna.ats.jta] (default task-18) TransactionSynchronizationRegistryImple.getTransactionKey

example code:

@Stateless
@TransactionManagement(TransactionManagementType.BEAN)
public class A{
  @Inject
  private B b;
  @Inject
  private UserTransaction trx;
  
  public void foo(){
    trx.begin();
    //transaction is active
    b.bar();
    trx.commit();
  }
}
@Stateless
@TransactionManagement(TransactionManagementType.BEAN)
public class B{
  public void bar(){
    //transaction is closed
    //whatever
  }
}

Happens on JBoss EAP 7.0.9.

I have this constellation in lots of places, but only here it breaks. Am I missing something basic? Where can I look for additional clues?

Community
  • 1
  • 1
Thomas
  • 624
  • 11
  • 28

1 Answers1

2

Short answer: BMTs don't get propagated to other beans using BMTs. It's simply not possible to have a transaction spanning code in both beans.

(Except if you hack the JBoss TransactionManager to always get the same DB transaction.)

Thomas
  • 624
  • 11
  • 28
  • Depending on your intentions so you would better use container managed transactions and SUPPORTS. – aschoerk Nov 27 '18 at 09:17
  • Yes, BMT transactions are one way: they can propagate out to a CMT bean, but no other transaction can propagate into a BMT bean (https://www.oreilly.com/library/view/head-first-ejb/0596005717/ch09s09.html) – Mehran Mastcheshmi Nov 27 '18 at 14:13
  • @aschoerk What do you mean with SUPPORTS? Is this a programming term? – Thomas Dec 03 '18 at 13:27
  • This is a form of container managed transactionpropagation. See: https://stackoverflow.com/questions/6437828/spring-transactions-with-supports-propagation – aschoerk Dec 03 '18 at 15:14