I’m using JPAContainer 1.2.1 for the first time and I’m hitting this exception:
Caused by: org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: vortex.model.Person.addresses, no session or session was closed
at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:383)
at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected(AbstractPersistentCollection.java:375)
at org.hibernate.collection.AbstractPersistentCollection.readSize(AbstractPersistentCollection.java:122)
at org.hibernate.collection.PersistentList.size(PersistentList.java:114)
at java.util.Collections$UnmodifiableCollection.size(Collections.java:998)
at vortex.model.tool.AddressTool.getPrimary(AddressTool.java:15)
...truncated....
The .getPrimary(AddressTool.java:15) call is “person.getAddresses()” where person is an EntityItem from JPAContainer(Person.class)
and “getAddresses()” is a List of Address objects.
The relevant code is approximately:
container = new JPAContainer<Person>(Person.class);
logst.debug(m, "Creating EntityProvider");
MutableLocalEntityProvider<Person> entityProvider =
new MutableLocalEntityProvider<Person>(Person.class,
getEntityManager());
container.setEntityProvider(entityProvider);
// In a later function inside of a Table we get the person object that is selected
Person person = container.getItem(itemId).getEntity();
// Then we read various attributes of person and stuff those into different Components
person.getFirstName(); // String
person.getLastName(); // String
// Then we pass person.getAddresses() to AddressTool.getPrimary() which does
if (addresses == null || addresses.size() == 0)
return null;
// The call to addresses.size() triggers the exception
Prior to the addresses.size() call I’ve put in debug code which shows the EntityManager isOpen=true and the EntityManager.Transaxtion isActive=true.
Attached are Person and Address classes.
I’m using Hibernate 3.5.7 as the entitymanager.
Anybody have any suggestions on this? Perhaps my JPA annotations in Person are wrong???
Thanks in advance.
mike
12000.java (11.4 KB)
12001.java (7.25 KB)