-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 
Author Message
 Post subject: Hibernate LazyInitializationException
PostPosted: Tue Dec 28, 2004 4:31 am 
Newbie

Joined: Sun Dec 12, 2004 5:13 am
Posts: 10
Location: Vicenza,Italy
Hibernate version: 2.1.7

Hi all!
I'm tourble, i have a little question.
Suppose that i have a normal lazy initialization like this

<class
name="it.axiosinformatica.webward.hibernate.TprofProfili"
table="TPROF_PROFILI"
>

<id
name="iprofid"
type="java.lang.Integer"
column="IPROFID"
>
<generator class="assigned" />
</id>

<property
name="iprofcodice"
type="java.lang.String"
column="IPROFCODICE"
length="5"
>
</property>
<property
name="iprofdescr"
type="java.lang.String"
column="IPROFDESCR"
length="40"
>
</property>

<!-- Associations -->

<!-- bi-directional one-to-many association to TacceAccessi -->
<set
name="tacceAccessis"
lazy="true"
inverse="true"
cascade="none"
>
<key>
<column name="IPROFID" />
</key>
<one-to-many
class="it.axiosinformatica.webward.hibernate.TacceAccessi"
/>
</set>
</class>

All right?

Now, i load the parent class TprofProfili in this mode

public class FinderUtil {

public Object findById(Class theClass, Integer id)
throws HibernateException {

net.sf.hibernate.Session hibSession = it.axiosinformatica.webward.hibernate.util.Session.currentSession();

Object retval = hibSession.load(theClass, id);

it.axiosinformatica.webward.hibernate.util.Session.closeSession();

return retval;
}

I have used the reflection (theClass is TprofProfili).

All seems to work fine (and i have close the session).

And the problem:

In the application i need to load TprofProfili's child table (tacceAccessis).

Good!

I do this:

net.sf.hibernate.Session hibSession = it.axiosinformatica.webward.hibernate.util.Session.currentSession();

Set s = tprofProfili.getTacceAccessis();

it.axiosinformatica.webward.hibernate.util.Session.closeSession();

It shoud works, but hibernate retrive me a LazyInitializationException.

Why? Can i load childs in a second moment? Why not?

Somebody helps me.

Thanks

P.S. Sorry for my bad english!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 28, 2004 4:51 am 
Newbie

Joined: Wed Feb 25, 2004 11:41 pm
Posts: 19
Location: China
when u close ur first session..
tprofProfili object was a Transient Object!
So ur child-collection, It cant be initialized in ur new session...

hth

_________________
who can tell me why?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 28, 2004 5:42 am 
Newbie

Joined: Sun Dec 12, 2004 5:13 am
Posts: 10
Location: Vicenza,Italy
Thaks!
So, if i wants load childs in a next step, what should i do?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 28, 2004 5:38 pm 
Newbie

Joined: Sun Dec 12, 2004 5:13 am
Posts: 10
Location: Vicenza,Italy
What should i do to load childs in a second step (into a new session)??

Is it possible?


Top
 Profile  
 
 Post subject: Session invalid
PostPosted: Tue Dec 28, 2004 6:30 pm 
Newbie

Joined: Wed Oct 13, 2004 11:23 am
Posts: 14
Your problem is you are trying to access child elements from parent .. but in different sessions. Your session should NOT be closed when you are accessing child elements from object of its parent.

Working scenario--

Session valid
- access parent
- now accedd child


Your scenario--
Session valid
-access parent
--access child {Session closed}


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 28, 2004 6:35 pm 
Newbie

Joined: Sun Dec 12, 2004 5:13 am
Posts: 10
Location: Vicenza,Italy
Thanks a lot!
Bye!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.