Works as designed:
  - for CDI methodB call by methodA is a simple internal method call, which 
typ. conformes to user expectation
  - alternative: use EJB _business method_, which will be intercepted also if 
cascaded

  Please note: @Transactional only starts transaction, if none is currently 
active (TxType.MANDADORY)
  see TxType.MANDATORY vs TxType.REQUIRES_NEW
  
https://docs.oracle.com/javaee/7/api/javax/transaction/Transactional.TxType.html
 
<https://docs.oracle.com/javaee/7/api/javax/transaction/Transactional.TxType.html>

  Please note the high overhead of intercepting every internal method call.
  Your example is perhaps instructive, but contrived.
  By annotating every method @Transactional, which needs to be transactional, 
your problem is easily solved.

  ---- [email protected] wrote ----
  &nbsp; > Hi,
>
>  I am using Weld (3.1.2) and Deltaspike (1.9.1) to drive Eclipselink JPA
>  (2.7.5)
>  My EntityManager producer produces request scoped entity managers
>
>  @Produces
>  @RequestScoped
>  protected EntityManager createEntityManager() {
>  return entityManagerFactory.createEntityManager();
>  }
>
>  I have a case where transaction is not getting started on
> @ApplicationScope
>  bean:
>
>  public MyBean{
>  @Inject private EntityManager em;
>
>  public void methodA{
>  ....
>  try{
>  methodB()
>  } catch {
>  // perform non DB rollback logic here
>  }
>
>  @Transactional
>  public void methodB{
>  //obtain and manipulate entities via em instance
>  // checking em.getTransaction().isActive() returns false
>  }
>  }
>
>  method methodA() gets called from Jersey resource
>  if I annotate the top level method methodA as @Transactional everything
>  works however when methodB is annotated and called from methodA no
>  transaction is started
>
>  while my usage is a bit fishy (what if transaction is started before
>  calling methodA but it works for this particular case and I have checks
>  for it not to be ran in existing transaction) still I would expect
> methodB
>  to start transaction.
>
>  Any suggestions is appreciated.
>
>  Thank you,
>  alex
>  &nbsp;

Reply via email to