-->
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.  [ 7 posts ] 
Author Message
 Post subject: Hibernate Query that doesn't return One-Many relation objs
PostPosted: Thu Feb 12, 2009 10:58 am 
Newbie

Joined: Tue Jul 22, 2008 5:11 pm
Posts: 16
I have JPA entity (Object A) with a One-Many owning relationship (Object B) in an ArrayList.

I want to be able to query for Object A without having any of the instances of Object B returned (proxies or otherwise) in the One-Many ArrayList.

Is this possible? In rough pseudocode this is what I want:

"from ObjectA where ObjectA.id=5 DO NOT INCLUDE ObjectB"


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 12, 2009 11:20 am 
Regular
Regular

Joined: Fri Jan 30, 2009 10:10 am
Posts: 74
Location: London
So, you want an instance of Object A that is not a true representation of its actual state with relation to instances of Object B?

You've mentioned JPA, does this mean that you will not be wanting a native Hibernate solution?

How would expect the caching mechanisms to behave? Are there other areas of your application that are allowed to have proxies representing the list of Object B instances from Object A - normal behaviour?


--
Stephen Souness


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 12, 2009 11:34 am 
Newbie

Joined: Tue Jul 22, 2008 5:11 pm
Posts: 16
A hibernate solution is fine.. I am looking for any solution; although I'd prefer a JPA solution, but I am using Hibernate as the JPA implementation.

I'd like to give the option of returning only "ObjectA" without it's relationship or the full ObjectA.

I am not very concerned with the Caching aspect of this (yet).

I would rather not have any ObjectB proxies involved. I want an ObjectA instance returned with the ObjectB arrayList either null or empty.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 12, 2009 11:46 am 
Regular
Regular

Joined: Fri Jan 30, 2009 10:10 am
Posts: 74
Location: London
I'm a little curious about why you want this behaviour. You won't be significantly reducing data traffic between your application and the database, as Hibernate typically finds the count of Object B instances and sets up a single proxy for lazy loading - so memory shouldn't be an issue either.

Are you going to be performing any updates on the retrieved instances of Object A? If so, you will also need to consider how to not effect the relationship with the Object B instances on update, but still effecting them if there is going to be deletion of Object A instances (since you've mentioned that the Object B instances belong to the Object A instances).


--
Stephen Souness

(PS: Sorry for having more questions than answers at this point)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 12, 2009 11:53 am 
Newbie

Joined: Tue Jul 22, 2008 5:11 pm
Posts: 16
Thank you for all of your help. You bring up some good issues.

I will not be performing any updates on the retrieved instances of Object A. The objects will be accessed over RMI (henced Serialized) so the proxies are not necessary.

There will be one process inserting/updating/deleting ObjectA's from the database, and a slew (10+) of other services/processes/computers querying that data over RMI. Some other services only require the ObjectA instance; while some will require attached ObjectB instances. I do not want to include any unnecessary data to the remote services.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 12, 2009 12:07 pm 
Regular
Regular

Joined: Fri Jan 30, 2009 10:10 am
Posts: 74
Location: London
Is it feasible to create a Data Transfer Object to represent the Object A instances to the RMI clients?

--
Stephen Souness


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 12, 2009 12:12 pm 
Newbie

Joined: Tue Jul 22, 2008 5:11 pm
Posts: 16
I'd rather not. Ideally I would just return ObjectA with the ObjectB ArrayList null or empty.


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