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.-