2012-05-22 110 views
1

我有两个表,用户和产品。并试图自动创建一个新的表TestedProducts,这是用户和产品之间的多对多关系。但是,我得到这个错误。JPA ManyToMany问题

org.apache.jasper.JasperException: javax.ejb.EJBException: The bean encountered a non-application exception; nested exception is: 
<openjpa-1.2.1-r752877:753278 fatal user error> org.apache.openjpa.persistence.ArgumentException: 
"ejb.UserEntity.products<element:interface ejb.Product>" has columns with targets, but OpenJPA does not support any joins on this mapping in this context. 

UserEntity看起来很简单。

long id; 

String firstname; 
String lastname; 
String password; 
String email; 
String description; 

List<Product> products; 

public void setId(long id){ 
    this.id = id; 
} 

@Id 
@GeneratedValue 
public long getId() { 
    return id; 
} 

@ManyToMany 
@JoinTable(name="TestedProducts", 
joinColumns= 
    @JoinColumn(name="usrId", referencedColumnName="id"), 
    inverseJoinColumns= 
    @JoinColumn(name="prodId", referencedColumnName="id") 
) 
    public List<Product> getProducts() { 
    return products; 
    } 

    public void setProducts(List<Product> products) { 
    this.products = products; 
    } 

而且ProductEntity这样的:

long id; 

String name; 
String description; 
String type; 

List<User> users; 

@ManyToMany(mappedBy="products") 
protected List<User> getUsers() { 
    return users; 
} 

protected void setUsers(List<User> users) { 
this.users = users; 
} 

我跳过了getter和setter方法的其余部分。

回答

0

您需要在产品实体中以与您在用户实体中相同的方式注释包含用户的列表,只能反转。我不认为mappedby值处理相同。

+0

我认为这可能是问题,没有时间来测试它虽然 – Zeezer