Entity collection problem.
Hello
I try to get a many relationship collection of the Enitty language. Unfortunately I get an error message.
@OneToMany(cascade={CascadeType.ALL})
@JoinColumn(name="langid")
public Collection<Assortment> getAssortments() {
return assortments;
}
public void setAssortments(Collection<Assortment> assortments) {
this.assortments = assortments;
}
used by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.apache.myfaces.el.PropertyResolverImpl.getProperty(PropertyResolverImpl.java:400)
... 56 more
Caused by: org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: org.flohmarkt.ejb.Language.assortments, no session or session was closed
at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:358)
at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected(AbstractPersistentCollection.java:350)
at org.hibernate.collection.AbstractPersistentCollection.readSize(AbstractPersistentCollection.java:97)
at org.hibernate.collection.PersistentBag.size(PersistentBag.java:222)
at org.flohmarkt.web.WelcomePage.getLeftOverviewList(WelcomePage.java:69)
... 61 more
An unresolved lazy relationship can only be obtained from an attached entity. An attached entity is one gotten from an entity manager within a transaction, a session bean method for example.