Is there a CDI callback like @PostConstruct
but that is instead invoked after the class is put into service?
I have a UserDAO
that injects a EntityManager
and a EJB UserBean
that injects the UserDAO
, which is invoked remotely.
When the UserBean.save(u)
is invoked, it is executed within the transactional EJB scope. But the EntityManager
injected into UserDAO
isn't associated with the transaction by the injection time.
If I declare a init method in the UserDAO
and annotate with @PostContruct
, the TransactionSynchronizationRegistry
isn't the same when the EJB method is invoked due to the @PostConstruct
nature.
This is all correct, because the @PostConstruct
callback is defined as "Initializing a managed bean specifies the lifecycle callback method that the CDI framework should call after dependency injection but before the class is put into service."
But, if I use the TransactionSynchronizationRegistry
inside the method UserDAO.update(u)
, the transaction is the same as UserBean
.
So, is there a callback method/annotation that I can use after the bean is put "into service"? That way I'd be able to put this method in the UserDAO
, so I can use the TransactionSynchronizationRegistry
before any method invocation of UserDAO
.
Edit:
The JTA transaction is created when my userBean.save(u)
method is invoked. But at @PostContruct
time of UserDAO
I'm able to inject a valid instance of TransactionSynchronizationRegistry
, but it is a different transaction with status STATUS_NO_TRANSACTION
and another transaction-id (different from transaction from userBean.save(u)
). But I would like to use some informations about the same transaction that originated from the invocation of the userDAO.save(u)
method in the @PostConstruct
method of UserDAO
.
PS: English is not my main language. I'm sorry if I did not make myself clear enough.