开发者

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜