LazyInitializationException EJB3

Hello,

Please forgive the perhaps obvious questioning, but I'm very new to EJB's and have only started to get my head around them.

I'm getting the following error:

org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: contentspk.Content.set, no session or session was closed

My setup is JBoss, I'm using EJB3.

The structure is an Entity bean, Content, which works fine normally. This has a Collection set, which is a Comment Entity bean. The mapping is a OneToMany.

The problem arises when I call the get method for this Collection.

I have Googled and heard about having to use 'TX'? I have yet to need to use whatever this so am a bit lost....

Any help would be great! :-)

Many thanks,

Terry

[805 byte] By [not_terrya] at [2007-11-26 18:25:48]
# 1

Terry, I got the same problem as you...Was puzzled for the whole day. I am new at Hibernate/EJB 3 myself as well.

I was able to solve it however: You can change fetch mode (Lazy by default) to EAGER. That will work!

Here is my code example:

@OneToMany(mappedBy= "facilityQuestionId",fetch=FetchType.EAGER)

private Collection<Answer> answerCollection;

TheOthersa at 2007-7-9 5:59:51 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...