I have three entities: Category, Item and User.They have a ternary relationship with each others (this is an example in Java Persistence With Hibernate).
The mapping of Category entity:Code:
@ManyToMany
@MapKeyManyToMany(joinColumns = @JoinColumn(name = "ITEM_ID"))
@JoinTable(name = "CATEGORY_ITEM",
joinColumns = @JoinColumn(name = "FK_CATEGORY_ID"),
inverseJoinColumns =
@JoinColumn(name = "FK_USER_ID"))
private Map<Item, User> items = new HashMap<Item, User>();
The mapping of Item:Code:
@ManyToMany(mappedBy = "items")
public Set<Category> getCategories() {
return categories;
}
The schema which is generated by hbm2ddl is very strange, instead of generating a table with a composite key of foreign keys to CATEGORY, ITEM tables and a foreign key to USER table, it doesn't do so.
Here is the structure of generated table:Anyone can tell me this incorrect generated schema due to my incorrect mapping or a bug in hibernate. I have tried to test with hibernate 3.2.5 and 3.3.1.
Thanks in advance.