In some object-mappings, I have collections of subobjects:
Code:
<class name="MainObject"....>
...
<bag name="subList" cascade="save-update" lazy="false" inverse="true">
<key column="ID"/>
<one-to-many entity-name="SubObject"/>
</bag>
</class>
In some cases, these subobjects have different types,
e.g.
Code:
public class SubObjectType1 extends SubObject
The subobject-types are stored on different tables as the super-object (I don't use discriminators)
and they are declared as <joined-subclass in the corresponding mapping.
For reading the subList in the MainObject, I use Join-Fetching.
Reading the MainObject results in the following second SQL-Statement for the collection:
Code:
SELECT ...
FROM SubObject s
LEFT OUTER JOIN SubObjectType s1 ON s.ID = s1.ID
WHERE s.ID = 'xxxxxxx';
Is it possible to add an additional restriction to the LEFT OUTER JOIN so that the statement will look like this:
Code:
SELECT ...
FROM SubObject s
LEFT OUTER JOIN SubObjectType s1 ON s.ID = s1.ID [b]AND s.orgUnit = s1.orgUnit[/b]
WHERE s.ID = 'xxxxxxx';
I think if I use a composite-id in the mappings, this query will be generated automatically.
But is there a way to do this without using a composite-id - maybe with another fetching-strategy?