gpt4 book ai didi

java - JPA2 :i use a JoinColumn as queryparam to create a query and a exception occurred , 为什么

转载 作者:行者123 更新时间:2023-12-02 08:07:10 25 4
gpt4 key购买 nike

    @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编写一个查询。如下所示:

 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].

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

最佳答案

在查询中

b.want_uid

需要更改为

b.wantUid

所以,

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

关于java - JPA2 :i use a JoinColumn as queryparam to create a query and a exception occurred , 为什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7984832/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com