FetchType using ManyToAny Annotation
Jean-Luc Scheefer <[email protected]> Mon, 05 Jan 2009 16:55:19 +0100
| Newsgroups | gmane.comp.windows.dotnet.nhibernate.devel |
|---|---|
| Message-ID | <[email protected]> |
Hi,
After many searches, I couldn't get a solution for the following exception :
org.hibernate.LazyInitializationException - failed to lazily initialize =
a collection of role: user.data.UserTypeImpl.maps, no session or session =
was closed
[java] org.hibernate.LazyInitializationException: failed to lazily =
initialize a collection of role: user.data.UserTypeImpl.maps, no session =
or session was closed
[java] at =
org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializati=
onException(AbstractPersistentCollection.java:380)
[java] at =
org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializati=
onExceptionIfNotConnected(AbstractPersistentCollection.java:372)
[java] at =
org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPe=
rsistentCollection.java:365)
[java] at =
org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersiste=
ntCollection.java:108)
[java] at =
org.hibernate.collection.PersistentMap.entrySet(PersistentMap.java:265)
When trying to get the wrapping object.
Considered that I have the user.data.UserTypeImpl Object with a map =
inside. Here's the declaration of the map field :
@ManyToAny(metaColumn =3D @Column(name =3D "MAPS_TYPE"), fetch=3DFetchType.=
EAGER)
@AnyMetaDef(idType =3D "long", metaType =3D "string",
metaValues =3D {
@MetaValue(targetEntity =3D UserTypeImpl.class, value =3D "USERTYPEIMPL"),
@MetaValue(targetEntity =3D UserTypeImpl2.class, value =3D "USERTYPEIMPL2"),
@MetaValue(targetEntity =3D UserTypeImpl3.class, value =3D "USERTYPEIMPL3")
})
@JoinTable(joinColumns =3D @JoinColumn( name =3D "MAPS_ID" ),
inverseJoinColumns =3D @JoinColumn( name =3D "USERTYPE_ID" ))
@MapKey
private Map<String,UserType> maps =3D new HashMap<String, UserType>();
The problem is around the fetchType of the @ManyToAny annotation. It =
seems that the EAGER type is not supported or recognized for this =
annotation.
I tried with the @OneToMany tags and it worked.
So my question is : why do I have this exception ? and is there any way =
to do this kind of Polymorphic map with an EAGER fetching strategy ?
Thank you.
-- =
Jean-Luc Scheefer
Software Development Engineer
[email protected]
Phone : + 33 (0)4 92 38 53 84
ACTIVEEON - http://www.activeeon.com
2004, route des Lucioles =96 B.P.93
06902 SOPHIA ANTIPOLIS CEDEX (France)
---------------------------------------------------------------------------=
---