-->
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: How to tell Hibernate NOT to load childs
PostPosted: Wed Dec 17, 2003 4:17 am 
Newbie

Joined: Thu Sep 25, 2003 9:25 am
Posts: 15
In my code I use both native SQL and HQL. My mapping is:

Code:
<class name="User" table="users">
...
<set name="attributes" inverse="true" lazy="true" cascade="all">
<key column="userId" />
<one-to-many class="Attribute" />
</set>
</class>


I load User object using Hibernate: session.load(...)
Because lazy is true in attributes set, the attributes are not loaded. Next, I fetch the attributes with native SQL query by hand (ie. not using Hibernate) and setting them one by one to User object with:

Code:
Set ua = user.getAttributes();
ua.add(a);
user.setAttributes(ua);


Unfortunately what happens here is that when I call user.getAttributes() they are all loaded by Hibernate (of course!!) and this is exactly what I DON'T want. Is there any way to prevent Hibernate from loading the attributes in this case (there are cases where I DO need Hibernate to load the attributes)?

I think this is impossible, but someone please correct me if I'm wrong (I sure hope so!!)

Thanks!

ps. this is just an example of my problem, my real code is not that simple, but you get the idea of the problem here... :)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 17, 2003 6:20 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
You should be able to make Atribute a proxy class, therby lazy loading it on demand. You should be able to use a explicit join fetch in HQL if you want to load everything.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 17, 2003 8:21 am 
Newbie

Joined: Tue Dec 16, 2003 9:57 am
Posts: 13
Hi,
what happens if you do this?

Set ua = new <your-type-of-set>Set();
ua.add(a);
user.setAttributes( ua );

Then you're not loading the attributes from the user object, right?

Regards,
Ola


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.