-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: ManyToMany with Composite Key
PostPosted: Fri Nov 12, 2010 6:58 am 
Newbie

Joined: Fri Nov 12, 2010 6:24 am
Posts: 1
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.