Reputation: 12214
class A{
private List<B> bs;
...
}
class B{
private Long id;
private String name;
...
}
And I'd like to have this:
class A{
// the map should have B.name as key
private Map<String,B> bs;
...
}
class B{
private Long id;
private String name;
private A a;
...
}
I don't know if it is clear what I'd like to do, but it is as simple as mapping a one to many relationship to a Map with the name of B as the key of the map.
Thanks in advance, Neuquino
Upvotes: 1
Views: 1271
Reputation: 61414
Try the hibernate annotation MapKey
@MapKey(name = "name")
@OneToMany()
private Map<String,B> bs;
Upvotes: 4