Hello All,
I've run across a problem that I'm having a little trouble conceptualizing how I'd implement a solution for using Hib/JPA annotations. The database model that we're looking to achieve is one that contains a join table with a composite key composed of two foreign keys and a third column (we'll call this "type"). So, any combination of entity X, Y, and "type" Z is unique.
A simplified example of how we'd want to use this would be to have a Person object that can have multiple Address objects, but the combination of an Address and it's type is unique. My conceptualization fails in that what we're looking for is the following:
class Person Set<Address+type> addresses
class Address Set<Person>
Using either the Address or the "type" as a key in a Map is not sufficient, since it wouldn't ensure uniqueness between the all three variables (i.e. the three-way composite key).
I've tried several permutations of @ManyToMany, @JoinTable, and @MapKey/@MapKeyManyToMany, but haven't been able to get this one right. Any thoughts?
Thanks in advance!
|