-->
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.  [ 3 posts ] 
Author Message
 Post subject: Is my lazzy collection initialized
PostPosted: Tue Jul 13, 2004 2:38 pm 
Regular
Regular

Joined: Mon Jun 14, 2004 1:42 pm
Posts: 80
Location: Brazil
I have a set mapping one to many relationship, with lazy initialization.

Code:
<set
   inverse="true"
   lazy="true"
   name="EspecialidadeMedica"
   where="Chvtpespec=1"
>
   <key column="chvpfisica" />
   <one-to-many class="Especialidade" />
</set>


My client code don't know if the set was initialized. Is there a way to check it avoiding the "no session associated" exception ?

Code:
//Current code

boolean isLoaded=false;
if (!myObj.getEspecialidadeMedica().isEmpty()) {
  isLoaded=true;
}

// Something like that, but is this bad ? bcause I'm referencing an internal
// hibernate class I think

PersistentCollection col =  (PersistentCollection) myObj.getEspecialidadeMedica();
if ( col.wasInitialized()) {
  isLoaded=true;
}


something using the session will not work (?) since the object is already detached.

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 13, 2004 4:36 pm 
Senior
Senior

Joined: Sun Jan 04, 2004 2:46 pm
Posts: 147
Code:
Hibernate.isInitialized( myObj.getEspecialidadeMedica() )


should do the trick.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 13, 2004 4:53 pm 
Regular
Regular

Joined: Mon Jun 14, 2004 1:42 pm
Posts: 80
Location: Brazil
Great! this method will be very usefull !!!! Thanks alot!


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