Hi All,
I have an instance where I want to retrieve only a partial object graph, but can't seem to work out how to do it.
Here is the scenario:
I have an Order class that contains many products. At times, I want to retrieve the order and ALL of its products, and other times, I want to retrieve the order and only ONE of it's products. The example below is a simplification of my REAL graph where the Product class also contains several one-to-many relationships, thus the reason why I only want ONE product so that I can cut down on the amount of data that I retrieve at a given time.
Below are my classes:
So, my question is how can I do it? I have tried creating a criteria object as shown below. Hibernate creates the select statement correctly, but then immediately creates another select statement that retrieves ALL of the products, thus nullifying the first select. Is there some way of telling hibernate not to try to eagerly retrieve all of the products? And if I set the FetchType to lazy, even then when I call getProducts( ) it retrieves ALL of the products.
Thanks,
Steve