Hi Forum,
I'm getting an org.hibernate.LazyInitializationException but I don't know why.
I've a method within an Stateless Bean (EJB3.0) which is annotated with transaction attribute NOT_SUPPORTED. When I query the database
I'll get the correct instance, but when I call a method "entity.getSomeCollection" I'll will get the org.hibernate.LazyInitializationException. It's kind of strange because I used this mechanism in the same way a thousand times before.
Here some code
Code:
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
public StructureNode someMethodName(....){
/* Code removed because it is unnecessary */
actualAssociatedNode = (StructureNode) em.createQuery(GET_STRUCTURE_NODE_BY_INTERNAL_SEARCH_KEY).
setParameter("businessKey", ouSrcSystemBusinessKey.concat(ouStructureKey)).
getSingleResult();
/************************************************
NEXT LINE THROWS THE EXCEPTION
************************************************/
actualAssociatedNode.getChildNodes();
/* Code removed because it is unnecessary */
}
The method is called by another public method within the same bean (also TransactionAttributeType.NOT_SUPPORTED), if you need to know. Within the calling method I do the same and this works!! Why it doesn't work here??? I'm stuck
Thx for suggestions
EDIT: Some further information: It works when I set the TransactionAttribute to REQUIRED or REQUIRES_NEW, but I don't want to open a transaction for reading access!! Does I have to?