Java Mailing List Archive

Home » the NHibernate development list »

[NHibernate-development] FetchType using ManyToAny Annotation

Jean-Luc Scheefer


Author LoginPost Reply

After many searches, I couldn't get a solution for the following exception :

org.hibernate.LazyInitializationException - failed to lazily initialize
a collection of role:, no session or session
was closed
[java] org.hibernate.LazyInitializationException: failed to lazily
initialize a collection of role:, no session
or session was closed
[java] at
org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException (
[java] at
org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected (
[java] at
org.hibernate.collection.AbstractPersistentCollection.initialize (
[java] at (
[java] at
org.hibernate.collection.PersistentMap.entrySet (

When trying to get the wrapping object.

Considered that I have the Object with a map
inside. Here's the declaration of the map field :

@ManyToAny(metaColumn = @Column(name = "MAPS_TYPE"), fetch=FetchType.EAGER)
@AnyMetaDef(idType = "long", metaType = "string",
metaValues = {
@MetaValue(targetEntity = UserTypeImpl.class, value = "USERTYPEIMPL"),
@MetaValue(targetEntity = UserTypeImpl2.class, value = "USERTYPEIMPL2"),
@MetaValue(targetEntity = UserTypeImpl3.class, value = "USERTYPEIMPL3")
@JoinTable(joinColumns = @JoinColumn( name = "MAPS_ID" ),
inverseJoinColumns = @JoinColumn( name = "USERTYPE_ID" ))
private Map<String,UserType> maps = 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
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
Phone : + 33 (0)4 92 38 53 84

2004, route des Lucioles – B.P.93

Nhibernate-development mailing list
©2008 - Jax Systems, LLC, U.S.A.