views:

92

answers:

1

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.

A: 

Try using company as your MapKey:

public class Product{
@OneToMany
@MapKey(name="company")
private Map<Company,ProductCompany> productCompanies=new HashMap<Company,ProductCompany>();
}
pedromarce