Hallo there,
I've got the following problem:
There are 3 classes: Team, Member and the associative class TeamMembership
Every member belongs to only one team, so there's a one-to-one association between Member and TeamMembership.
Every Team can have one or more Members, so there's a many-to-one association between Team und TeamMembership.
My mapping looks like this:
Member:
Code:
<one-to-one name="teamMembership" property-ref="member" cascade="delete" />
Team
Code:
<set name="teamMemberships" table="TeamMembership" inverse="true" cascade="all">
<key column="team_id" not-null="true" foreign-key="fk_team" on-delete="cascade" />
<one-to-many class="TeamMembership" />
</set>
TeamMembership
Code:
<many-to-one name="team" column="team_id" foreign-key="fk_team" class="Team" not-null="true" />
<many-to-one name="member" column="member_id" foreign-key="fk_member" class="Member" not-null="true" />
This mapping works, but now I want to use the 2nd-Level-Cache for all objects. It works too, except the case that I load a TeamMembership from a Member. It results in the following sql-statement:
Code:
select
teammembership.team_id,
teammembership.member_id,
...more properties...
from
teammembership
where
teammembership.member_id=?
Because member_id isn't the primary key of TeamMembership the 2nd-Level cache can't be used in this case.
But I think there must be a solution to use the 2nd-Level-Cache for all objects and associations!?
Is there a mistake in my Mapping? Do I have to map the association in another way?
Thanks for all replys!
kind regards
Peter