-->
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.  [ 3 posts ] 
Author Message
 Post subject: Map with keys being property of a related class
PostPosted: Wed Apr 28, 2010 5:50 am 
Newbie

Joined: Tue Apr 27, 2010 10:11 am
Posts: 3
I am struggeling with mapping to a map where keys should be a property of a related class rather than the class itself.

Assume there is a Person table/class (with PersonID, firstName, lastName) and a Dessert table/class (with DessertID and Name) -- this is just an example for illustration, adapted from another blog post. Person is supposed to have a map that assigns a rank to each dessert, so there is also a DesserRanking table/class (DessertRankingID, PersonID, DessertID, ranking) and the Java class is something like:
Code:
class Person
{
    ...
    Map<Desert, int> dessertRankings; /* dessert object -> ranking */
    ...
}


I can make the mapping for this fine where the relevant part is
Code:
<map name="DessertRankings" table="DessertRanking">
   <key column="DessertRankingID" />
   <index-many-to-many class="Dessert" column="DessertID" />
   <element column="ranking" type="int" />
</map>


However, I cannot figure out how to change the mapping if I want the map keys to be the dessert name, rather than the dessert object itself. So the class is like
Code:
class Person
{
    ...
    Map<String, int> dessertRankings; /* dessert name -> ranking */
    ...
}


I would not want to change the underlying database schema. Of course it would be easy to pull dessert name into the DesserRanking table instead of a foreign key reference, but I would not see that as a solution.

Can this be done? Any hints and help appreciated.

J.-


Top
 Profile  
 
 Post subject: Re: Map with keys being property of a related class
PostPosted: Thu Apr 29, 2010 6:10 am 
Newbie

Joined: Tue Apr 27, 2010 10:11 am
Posts: 3
/bump

Anyone has an idea on this? If someone knows definitively that this cannot be done, then please say so.

I have a vague feeling that this should be doable, but do not manage to get it working.

J.-


Top
 Profile  
 
 Post subject: Re: Map with keys being property of a related class
PostPosted: Mon May 03, 2010 9:55 am 
Newbie

Joined: Tue Apr 27, 2010 10:11 am
Posts: 3
Hm, no replies on this one. I guess it means that this cannot be done. What a pitty.

I would really like to hear any thoughts on workarounds or alternative approaches to the issue.

J.-


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

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.