Hibernate Map Mapping Problem
Hi I am trying to Persist a Map in Hibernate as开发者_运维百科 follows:
public class Product{
@OneToMany
@MapKey(name="id")
private Map<Company,ProductCompany> productCompanies=new HashMap<Company,ProductCompany>();
}
public class Company{
private int id;
}
public class ProductCompany(){
@ManyToOne
private Product product;
@ManyToOne
private Company company;
}
Any idea what the correct annotation would be for doing this mapping? At the moment it stores the keyset as ints...not as Company objects.
Thxs.
Try using company as your MapKey:
public class Product{
@OneToMany
@MapKey(name="company")
private Map<Company,ProductCompany> productCompanies=new HashMap<Company,ProductCompany>();
}
Try to build your project , before executing commands
精彩评论