开发者

Hibernate Map Mapping Problem

开发者 https://www.devze.com 2022-12-21 18:34 出处:网络
Hi I am trying to Persist a Map in Hibernate as开发者_运维百科 follows: public class Product{ @OneToMany

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

精彩评论

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

关注公众号