There are two entities: Person and Address, the Person has a lazy set of
Addresses.
Furthermore there are two stateless session beans: the PersonManager can create
and find Persons and the AddressManager can add new Addresses to the person.
Both beans have an EntittyManager injected. The AddressManager has an injected
PersonManager.
This is the code of the AddressManager invoked by the client:
@PersistenceContext
private EntityManager em;
@EJB
private PersonManager personManager;
...
public Address addAddress(Long personId, Address address) {
Person person = this.personManager.findPerson(personId);
this.em.persist(address);
person.getAddresses().add(address);
}
This is the exception:
org.hibernate.LazyInitializationException: failed to lazily initialize a
collection of role: com.qualitype.entity.Person.addresses, no session or
session was closed
I would say both methods (addChild and findPerson) are running in the same
transaction and sharing the same persistence context (even with two different
EntityManagers). So the set should be loaded on demand. Why not?
Has somebody an idea?
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3999080#3999080
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3999080
_______________________________________________
jboss-user mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/jboss-user