Ho scritto un metodo EJB stateless che consente di ottenere un'entità in modalità "sola lettura".Scollegare un'entità da un contesto di persistenza JPA (JPA 2.0/Hibernate/EJB 3/J2EE 6)
Il modo per fare ciò è ottenere l'entità con EntityManager e quindi scollegarla (utilizzando EntityManager JPA 2.0).
Il mio codice è il seguente:
@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;
}
}
Ottenere l'entità funziona bene, ma la chiamata al metodo detach
restituisce il seguente errore:
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)
non posso ottenere maggiori informazioni e non capisco qual è il problema ...
Qualcuno potrebbe aiutare?
Grazie! Ho appena aggiornato i miei JAR Hibernate a 3.5.0 CR2 e funziona benissimo. – Julien
L'operazione di scollegamento è ricorsiva (vale a dire in cascata)? –
@Guido - sì, se hai cascadeType = DETACH – Bozho