Reputation: 245
I want to inject the entityManager from Hibernate on an Hibernate Interceptor Class. I'm using EJBs and JBoss. The transaction is JTA and the provider is the org.hibernate.ejb.HibernatePersistence.
I tried to do it like that:
@Stateless(name = "HistoricInterceptor")
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public class HistoricInterceptorImpl extends EmptyInterceptor implements HistoricInterceptor {
@PersistenceContext(name = "windi")
private EntityManager em;
// overriden methods, etc
}
But the reference to entityManager is always null.
Is this behaviour expected? How can I access an entityManager from within an Interceptor class?
Upvotes: 0
Views: 356
Reputation: 245
I had given up on that exact solution. Instead, I've created another class that has the EJB Annotations. The interceptor will call that EJB by using a provider class that lookup up EJB classes on the context of the application. There, the entityManager is correctly associated.
Upvotes: 1