-->
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.  [ 5 posts ] 
Author Message
 Post subject: Problem with initialize / isInitialized on lazy loading coll
PostPosted: Wed Jun 07, 2006 5:10 am 
Newbie

Joined: Mon Jun 05, 2006 12:41 pm
Posts: 19
Hibernate version:
3.1

On lazy loading collections, i have the following problem in a class, assuming mySet is a lazy loading collection :

Code:
Set mySet = myObject.getMySet();
//here mySet has a value, and when i inspect it, it isn t initialized (initialized=false)

if (!Hibernate.isInitialized(mySet)){
     //logically, come here, because still not initialized, but property "isInitializing" is to true
     Hibernate.initialize(mySet);
    //here i have an hibernate error because of a second call of initialize on the object
}
if (mySet.iterator.hasNext()){
     my treatment
}


How may I solve the problem?
I don t think that my mapping or hibernateconfig are special, their code are like in the hibernate doc....


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 07, 2006 7:51 am 
Expert
Expert

Joined: Thu Sep 22, 2005 10:29 am
Posts: 285
Location: Almassera/Valencia/Spain/EU/Earth/Solar system/Milky Way/Local Group/Virgo Supercluster
try with this:
Code:
if (!Hibernate.isPropertyInitialized(myObject, "mySet")){
     Hibernate.initialize(myObject.getMySet());
}
Set mySet = myObject.getMySet();
if (mySet.iterator.hasNext()){
     my treatment
}


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 07, 2006 9:40 am 
Newbie

Joined: Mon Jun 05, 2006 12:41 pm
Posts: 19
Even with your modification results are the same...
I dont really have any idea of what could be the origin of the problem....


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 07, 2006 12:46 pm 
Expert
Expert

Joined: Thu Sep 22, 2005 10:29 am
Posts: 285
Location: Almassera/Valencia/Spain/EU/Earth/Solar system/Milky Way/Local Group/Virgo Supercluster
is the session you get myObject with open?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 07, 2006 1:27 pm 
Newbie

Joined: Mon Jun 05, 2006 12:41 pm
Posts: 19
Yes, the session is opened.

I ve just found the reason : in fact my database is used with another software, and some records where orhans in the relation (loss of integrity), so i had to put not-found="ignore" for the mapping many-to-one sided. by this way, when my lazy object initialized, it was ok!

I don t understand why the error message was this one, because during debug it was really showing a double call on "intialize"

Thanks for help..


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.