Is there a way in JPA to map an attribute with type Map<String, Set<Address>>
Given the following classes:
class Company {
int id;
Map<String, Set<Address>> addresses; // Key is the country of the Address
}
class Address {
int id;
String country;
}
There are three tables:
tbl_company
id INT
tbl_address
id INT
country VARCHAR(40)
tbl_company_address
company_id INT
address_id INT
How can I map this scenario with JPA
One of possible solutions is having an address-wrapping class, and insert Set into that class. In that case you will be able to use map (using @OneToMany, @MapKey annotations). E.g.
.. and AddressWrapper would contain
@OneToMany Set<Address> addresses;, along withString countryKey.