Including a JPA-Project in a JAX-RS REST-Service Application
jakarta-ee, jax-rs, jpa, persistence
Solution
Going to answer my own question. With the help of netbeans I gathered some information that made me change my project structure lightly.
This is what i've done:
- Giving the REST-Project the JPA-facet
- Store the persistence.xml in that project
- in the PU link to the jar which contains the entites
This way all i have to do is pass the injected entityManager into the entity-project and i am done!
Problem
I have written a JPA-Project which encapsulates all my entities. Since these entities are also needed in the REST-Service project I exported the JPA-Project as a *.jar and included it in the REST-project (this has no JPA-Facet). So everything can be deployed on the server and I can reach the REST-services from the frontend, but as soon as the EntityManager should be injected in a class nothing happens. This results in NullPointerExceptions since the entityManager is not present. The classes in which to inject are marked as `@Stateless` and the entityManager with the `@PersistenceContext` annotation. So the question is: does injection work in a nested project or do I have to instantiate the entityManager manually? Thanks in advance! In Addition, I am using Glassfish v 3.1.2 and JPA 2.0