-->
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.  [ 4 posts ] 
Author Message
 Post subject: How do I load the entity by id and exclude some property?
PostPosted: Tue Dec 19, 2006 3:24 pm 
Newbie

Joined: Tue Dec 19, 2006 3:02 pm
Posts: 4
Hello, it's an interesting dilemna that no one at my company seems to know the answer to. I have a simple entity called Parent and its corresponding class. The enity has a set property:

<set name="children" table="child" lazy="true" cascade="all-delete-orphan">
<key column="id" />
<one-to-many class="Child" />
</set>

The class Parent, has a method called getChildren(), which tries to load the associated children of class type Child.

So pretty simple so far. What if you want to load a specific Parent through criteria api by its id, but the children should be loaded for all properties defined in the Child enity except for one or two properties? The reason behind this is these entities are defined for different Parent types where in one case, you want to load the children with all properties defined in the Child entity mapping. In another case, you want to load all but 1 or 2. So in essense, I have a specific business case where I want to load the Children for all properties except property 1 and 2. This basically has to do with data issues and is outside of this topic.

I have set the lazy=true which will load all Parents successfully, however, when calling getChildren, it obviously tries to load the Child entity for each child and fails with "No row with the given identifier exists" error. Basically one of the keys is no longer valid and thus my need to load all children except for one of its properties. The record is still valid from a business case.

I'd be interested to see if anyone ever had to do this or knows the best way around this, hopefully through criteria api to be consistent with the rest of the code.

Thank you in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 19, 2006 5:15 pm 
Expert
Expert

Joined: Tue Jul 11, 2006 10:21 am
Posts: 457
Location: Columbus, Ohio
I suppose you could implement the ResultTransformer interface and do criteria.setResultTransformer(). Look in the org.hibernate.transform package for code examples.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 19, 2006 5:21 pm 
Newbie

Joined: Tue Dec 19, 2006 3:02 pm
Posts: 4
Appreciate it. I will look into it.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 24, 2006 11:09 pm 
Beginner
Beginner

Joined: Sat Dec 16, 2006 1:52 pm
Posts: 40
I dont fully understand your problem here. However, you can make all child properties lazy loaded, then let the application manually load each property of the child you want. I think props are all lazy by default anyway. So by default you get 0 loaded, then you can load the ones you want.

Not sure exactly what you want though, and I am new. But I do have situation where one class needs to be loaded "light", and then at other times "heavy".


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