0

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.

DD.
  • 21,498
  • 52
  • 157
  • 246

2 Answers2

0

Try using company as your MapKey:

public class Product{
@OneToMany
@MapKey(name="company")
private Map<Company,ProductCompany> productCompanies=new HashMap<Company,ProductCompany>();
}
pedromarce
  • 5,651
  • 2
  • 27
  • 27
-1

Try to build your project , before executing commands

lahbib
  • 119
  • 1
  • 6