-->
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: Preserving selection criteria when lazy loading to-many
PostPosted: Fri Aug 05, 2011 9:58 am 
Newbie

Joined: Fri Aug 05, 2011 9:37 am
Posts: 2
Sorry if this is documented, but I cannot even begin to compact this question into a sentence and searching didn't help. Here is the deal: I have a to-many table which has a field on which the query is based. When I lazy load the to-many relationship, all fields get lazy loaded and not just the one I based my selection on. I am trying to construct a json object from my hibernate objects that are returned based on a certain query.

Here is an illustration of the concept:

Table1: Owners
Table2: Car brands
Owners can have many cars (to-many relationship)

The query looks like this in pseudocode:

List owners = find Owners where brands.brandName = 'BMW'

I then get a list of Owners objects all of which correctly have a BMW. However, when I do something like

owners.get(0).getBrands()

it returns ALL the brands from the table, not just 'BMW' like I originally asked. I understand that this is how it probably should work, but I also realized that I have no idea how to make hibernate remember my criteria and load just that one row from the to-many relationship on which the query was based, which should be a fairly common operation.

Please suggest where I can look?


Top
 Profile  
 
 Post subject: Re: Preserving selection criteria when lazy loading to-many
PostPosted: Mon Aug 08, 2011 9:33 am 
Newbie

Joined: Fri Aug 05, 2011 9:37 am
Posts: 2
I thought of a better way to describe this:I want to lazy-load association arrays based on some criteria. Is there some way to limit the association set to a subset based on a certain criteria (Eg. brand='BMW' when fetching owner.getCarSet() association)?


Top
 Profile  
 
 Post subject: Re: Preserving selection criteria when lazy loading to-many
PostPosted: Thu Oct 06, 2011 11:13 am 
Newbie

Joined: Thu Oct 06, 2011 11:05 am
Posts: 1
Perfect description of your problem, actually I have the same issue, was wondering if you have found any neat solution for this in hibernate?!

thanks,


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.