I want to use the @PersistenceUnit annotation in my app to create an application managed EntityManager
Code:
@PersistenceUnit(unitName="primary")
private static EntityManagerFactory entityManagerFactory;
EntityManager entityManager = entityManagerFactory.createEntityManager();
This doesn't seem to be working. I run my code through a debugger and discover that entityManagerFactory is null. My guess is that the injection of Persistence context with the @PersistenceUnit annotation is not working.
My app is a CDI app - - I converted it to CDI by creating a beans.xml file in WEB-INF. I'm using JBoss 7. This is a basic struts hibernate project deployed by Maven. I'm only adding CDI so that I can inject the PersistenceUnit at this point in the code.
Is there anything I need to configure within CDI to get the annotation to work? Thanks.