JPA2:我使用JoinColumn作为queryparam来创建查询并发生异常,为什么

时间:2011-11-02 17:39:36

标签: java jpa ejb jpa-2.0

    @JoinColumn(name = "want_uid", referencedColumnName = "id")
    @ManyToOne
    private BookUsers wantUid;
    @JoinColumn(name = "sale_uid", referencedColumnName = "id")
    @ManyToOne
    private BookUsers saleUid;
    @JoinColumn(name = "book_id", referencedColumnName = "id")

此代码来自实体bean 我使用want_uid作为queryparam写一个查询.as fllows:

 BookUsers bookUsers=userDA.findUserByID(wantID);
 Query query= em.createQuery("SELECT b FROM BookOrder b WHERE b.want_uid = :want_uid");
 query.setParameter("want_uid", bookUsers);

发生了异常:

javax.servlet.ServletException: java.lang.IllegalArgumentException: An exception occurred while creating a query in EntityManager: 
Exception Description: Error compiling the query [SELECT b FROM BookOrder b WHERE b.want_uid = :want_uid], line 1, column 34: unknown state or association field [want_uid] of class [com.xbook.entities.BookOrder].

我没找到原因...... 你能告诉我吗 ? 感谢

1 个答案:

答案 0 :(得分:2)

在查询中

b.want_uid

需要更改为

b.wantUid

所以,

SELECT b FROM BookOrder b WHERE b.wantUid = :want_uid