Hi,
I'm trying to map a unidirectional many-to-many association. I want to retrieve Items from Category object. It works ok if the composite key in linking table forms out of Category PK and Item PK. However, if the linking table only has partial key from Category and pk from Item, then I gets the following error: A Foreign key refering Category from Item has the wrong number of column. should be 2
Table Schema Category ---[*] CategoryItem [*]--- Item categoryId(pk) categoryId itemId(pk) productId(pk) itemId
Class with annotation @Entity @Table(name="CATEGORY") public class Category { @EmbeddedId @AttributeOverrides( { @AttributeOverride(name="categoryId", column= @Column(name="categoryId")), @AttributeOverride(name="productId", column= @Column(name="productId")) } ) private CategoryId aCategoryId;
@ManyToMany(fetch=FetchType.EAGER) @JoinTable( name="CATEGORY_ITEM", joinColumns={@JoinColumn(name="categoryId")}, inverseJoinColumns={@JoinColumn(name="itemId")} ) private Set<Item> items; }
@Entity @Table(name="ITEM") public class Item { @Id private Long itemId; }
Where is my problem?
Thanks in advance for assistance.
|