gpt4 book ai didi

JPQL:状态字段路径无法解析为有效类型

转载 作者:行者123 更新时间:2023-12-04 10:00:42 25 4
gpt4 key购买 nike

我无法使此查询正常工作:

Query query = eManager.createQuery("select c FROM News c WHERE c.NEWSID = :id",News.class);
return (News)query.setParameter("id", newsId).getSingleResult();

我得到了这个异常(exception):
Exception Description: Problem compiling [select c FROM News c WHERE c.NEWSID = :id]. 
[27, 35] The state field path 'c.NEWSID' cannot be resolved to a valid type.] with root cause
Local Exception Stack:
Exception [EclipseLink-0] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.JPQLException
Exception Description: Problem compiling [select c FROM News c WHERE c.NEWSID = :id].

为什么会发生?
:id和命名参数相同

编辑:
我的实体类
@Entity
@Table(name="NEWS")
public class News implements Serializable{

@Id
@SequenceGenerator(name = "news_seq_gen", sequenceName = "news_seq")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "news_seq_gen")
private int newsId;
private String newsTitle;
private String newsBrief;
private String newsContent;
private Date newsDate;
@Transient
private boolean selected=false;

//constructor and getters and setters

最佳答案

发生这种情况是因为News实体没有名为NEWSID的持久属性。持久属性的名称在JPQL查询中区分大小写,并且应使用与实体中出现的大小写完全相同的大小写形式。

因为实体具有名为newsId的持久属性,所以也应在查询中使用它而不是NEWSID:

select c FROM News c WHERE c.newsId = :id

关于JPQL:状态字段路径无法解析为有效类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20056847/

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