-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: 2nd-Level cache with an associative class
PostPosted: Fri Oct 02, 2009 6:05 am 
Newbie

Joined: Fri Oct 02, 2009 5:08 am
Posts: 2
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.