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?
|