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