-->
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.  [ 9 posts ] 
Author Message
 Post subject: Restricting Hibernate from loading childs
PostPosted: Fri Jan 11, 2008 3:38 am 
Newbie

Joined: Thu Jan 10, 2008 8:39 am
Posts: 7
Hibernate version: 1.2

Problem Statement:
Is there any way to restrict Hibernate to stop loading Child objects while loading a Parent entity? Turning lazy="true" will not turn it off but loads the data at first access. I want to turn that off completely.

Thanking in advance for your replies.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 11, 2008 9:19 am 
Beginner
Beginner

Joined: Sun Nov 18, 2007 10:39 am
Posts: 46
Location: Liverpool, England
So do you just want to trigger a load manually when you want it, and still have support for NHibernate saving it? Not sure if there's a better way, but I guess you could set lazy to true and map the collection onto a protected property of your class. That way a user of the class would never be able to access the collection directly, and hence never force a load. You could then provide your own public property and use that to control access to the mapped property, if you see what I mean.

Does that sound any use, or have I completely missed what you were trying to achieve? :-)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 11, 2008 9:45 am 
Beginner
Beginner

Joined: Thu Oct 25, 2007 3:45 am
Posts: 22
kev160967 wrote:
Not sure if there's a better way, but I guess you could set lazy to true and map the collection onto a protected property of your class. That way a user of the class would never be able to access the collection directly, and hence never force a load.


I think Waqas is asking about Parent-Child class relation, not a collection. Example: when you have parent class Human and child class Programmer and tell Hibernate to load Humans, it loads Humans and Programmers.
I am looking for a solution, too.


Top
 Profile  
 
 Post subject: The exact Problem
PostPosted: Fri Jan 11, 2008 10:24 am 
Newbie

Joined: Thu Jan 10, 2008 8:39 am
Posts: 7
I'm talking about Collections and the Problem is following:

I need to serialize an object across a web-service and I also tried to unproxify it but that also is not working.

I tried to unproxify the object that I had just read from database using following code:
Code:
public static object Unproxy(object obj) {
            if (obj is INHibernateProxy) {
                LazyInitializer li = NHibernateProxyHelper.GetLazyInitializer((INHibernateProxy)obj);
                obj =  li.GetImplementation();
            }
            return obj;
        }


I'm in need of serializing an object whose class is in the data model and is used by NHibernate. I can't serialize it normally because NHibernate adds to it the CastleProject DynamicProxy and the side who is deserializing the entity can't depend on the data access assemblies like NHibernate and DynamicProxy.

Is there a way of getting rid of the proxy outside of the object?

OR in other words

Can I disable the fetching of collections of Child object?

Changing properties to protected isn't working at all in my case.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 11, 2008 10:29 am 
Regular
Regular

Joined: Wed Jan 25, 2006 1:11 am
Posts: 118
Location: Copenhagen, Denmark
How about not mapping it?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 11, 2008 12:51 pm 
Newbie

Joined: Thu Jan 10, 2008 8:39 am
Posts: 7
jta wrote:
How about not mapping it?


I want to persist data using the Collections but don't want to load it.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 14, 2008 4:50 am 
Regular
Regular

Joined: Fri Feb 18, 2005 3:34 am
Posts: 88
Location: Poland/Wrocław
waqas wrote:
I want to persist data using the Collections but don't want to load it.


Why not make the collection lazy (it's default currently...)? Making it lazy prevents children loading until you try to access them.

_________________
Please rate this post if you've found it helpfull
Roland


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 14, 2008 4:54 am 
Regular
Regular

Joined: Fri Feb 18, 2005 3:34 am
Posts: 88
Location: Poland/Wrocław
Another option might be to a filter with criteria that is always false... But it will require to remember each time to enable the filter.

_________________
Please rate this post if you've found it helpfull
Roland


Top
 Profile  
 
 Post subject: I got the solution.
PostPosted: Sun Jan 20, 2008 8:09 am 
Newbie

Joined: Thu Jan 10, 2008 8:39 am
Posts: 7
I have found the solution:

We can use where clause in collections mapping. I'm using "where 1=0" in the collections where I don't want to load children collections. No need to write a filter in this case.

Thanks for all of you in spending time for replies


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.