I have this class (combination 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 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 for one thing: it emis NULLinside read(). It seems that the grizzly bear (I use this server along with the Jersey test platform) does not introduce PersistenceContext. What am I doing wrong here?
source
share