2012-05-22 138 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