Java Mailing List Archive

http://www.gg3721.com/

Home » the NHibernate development list »

[NHibernate-development] FetchType using ManyToAny Annotation

Jean-Luc Scheefer

2009-01-05


Author LoginPost Reply
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.throwLazyInitializationException (AbstractPersistentCollection.java:380)
[java] at
org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected (AbstractPersistentCollection.java:372)
[java] at
org.hibernate.collection.AbstractPersistentCollection.initialize (AbstractPersistentCollection.java:365)
[java] at
org.hibernate.collection.AbstractPersistentCollection.read (AbstractPersistentCollection.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 = @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" ))
@MapKey
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
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
jean-luc.scheefer@(protected)
Phone : + 33 (0)4 92 38 53 84

ACTIVEEON - http://www.activeeon.com
2004, route des Lucioles – B.P.93
06902 SOPHIA ANTIPOLIS CEDEX (France)


------------------------------------------------------------------------------
_______________________________________________
Nhibernate-development mailing list
Nhibernate-development@(protected)
https://lists.sourceforge.net/lists/listinfo/nhibernate-development
©2008 gg3721.com - Jax Systems, LLC, U.S.A.