I have this class (mix of JAX-RS/Jersey and JPA/Hibernate):
public class Factory {
@PersistenceContext(unitName = "abc")
EntityManager em;
@Path("/{id}")
@GET
public String read(@PathParam("id") int i) {
return em.find(Employee.class, i).getName();
}
}
This is the unit test:
public class FactoryTest extends JerseyTest {
public FactoryTest() throws Exception {
super("com.XXX");
}
@Test
public void testReadingWorks() {
String name = resource().path("/1").get(String.class);
assert(name.length() > 0);
}
}
Everything is fine here except one this: em
is NULL
inside read()
. Looks like Grizzly (I'm using this server together with Jersey Test Framework) is not injecting PersistenceContext
. What am I doing wrong here?