I have one-to-many relationship defined in my Set object.
Code:
<bag name="points" inverse="true" lazy="false" cascade="all">
<key column="SETID"/>
<one-to-many class="PointSet" />
</bag>
and the composite key on the SetPoint object
Code:
<composite-id>
<key-property name="startDate"/>
<key-many-to-one name="point" lazy="false" class="Point"/>
<key-many-to-one name="set" lazy="false" class="Set"/>
</composite-id>
When I do a search for a Set hibernate generates a query to find a Set and then one query for each point - very inneficient.
When I change my composite key to this
Code:
<composite-id>
<key-property name="startDate"/>
<key-property name="pointId"/>
<key-many-to-one name="set" lazy="false" class="Set"/>
</composite-id>
And add many-to-one relationship
Code:
<many-to-one
name="point"
column="POINTID"
class="Point" not-null="true"
insert="false" update="false"/>
It works as expected. One query to find Set and one to find all the points for the Set, but the problem is when I'm adding new Point to Set and want to persist it because I have pointId and Point objects in my PointSet hibernate is saying that this two are different.
I think first approach is how it should be implemented, but is there a way to force a join so it does only a single select for all the points rather than one for each point.
Thanks