【发布时间】:2011-02-02 02:07:16
【问题描述】:
我编写了一个无状态 EJB 方法,允许以“只读”模式获取实体。
这样做的方法是使用 EntityManager 获取实体,然后将其分离(使用 JPA 2.0 EntityManager)。
我的代码如下:
@PersistenceContext
private EntityManager entityManager;
public T getEntity(int entityId, Class<T> specificClass, boolean readOnly) throws Exception{
try{
T entity = (T)entityManager.find(specificClass, entityId);
if (readOnly){
entityManager.detach(entity);
}
return entity;
}catch (Exception e){
logger.error("", e);
throw e;
}
}
获取实体工作正常,但调用detach 方法返回以下错误:
GRAVE: javax.ejb.EJBException
at ...
Caused by: java.lang.AbstractMethodError: org.hibernate.ejb.EntityManagerImpl.detach(Ljava/lang/Object;)V
at com.sun.enterprise.container.common.impl.EntityManagerWrapper.detach(EntityManagerWrapper.java:973)
at com.mycomp.dal.MyEJB.getEntity(MyEJB.java:37)
我无法获得更多信息,也不明白问题出在哪里......
有人可以帮忙吗?
【问题讨论】: