1
我是新手。EJB和澤西島之間的實體狀態
Jersey和EJB是否保持相同的EntityManager範圍?
我是否必須將EntityManager傳遞給EJB以獲得相同的持久性上下文?
主要目標用法是JTA。
@Stateless
class MyEJB {
public MyEntity find(Long id) {
...
}
@PersistenceContext;
EntityManager entityManager;
}
class MyResource {
@GET
@Path("/myentity/{id}");
public MyEntity get(@PathParam("id") final long id) {
final MyEntity found = myEjb.find(id);
// is found's state detached?
// should I have to reattach?
found.setDate(new Date());
return found;
}
@EJB
private MyEjb myEjb;
@PersistenceContext;
EntityManager entityManager;
}