-->
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.  [ 2 posts ] 
Author Message
 Post subject: Is it impossible to disable lazy loading?
PostPosted: Fri Dec 19, 2008 6:29 am 
Newbie

Joined: Thu Apr 28, 2005 6:48 am
Posts: 12
Location: Finland
Hello,

I have following entities:
Code:
class User {
   Integer id;
   Set<Role> roles;
}

class Role {   
   Integer id;
}


In my application I have logic layer and persistent layer.

Logic is executed outside of Hibernate session, so lazy loading cannot be used.

When business logic ask entities from persistent layer, it defines (in parameters) which associations must be initialized.

In one situation my business logic needs to load users with roles. This is OK. Persistent layer can load roles by using Hibernate join fetch.

In other situation my business logic needs to load users WITHOUT roles, and this is my problem. Hibernate sets lazy loading proxy collection as roles, I would like to get NULL value instead. In this situation role association must be kind of disabled.
Is this possible to do with Hibernate?


Hibernate gurus please help me.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 19, 2008 10:41 am 
Beginner
Beginner

Joined: Wed Dec 17, 2008 12:10 pm
Posts: 47
I'd be interested to know this as well. You can disable lazy loading on the collection (lazy="false" on the collection mapping). But, what happens then is the collection is initialized when the object is (obviously). It would be nice to be able to manage when the collection is loaded, but still have hibernate handle loading the collection. Something like session.initProperty("roles", user).


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