JPQL:状态字段路径无法解析为有效类型 [英] JPQL: The state field path cannot be resolved to a valid type
本文介绍了JPQL:状态字段路径无法解析为有效类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我无法使该查询生效:
Query query = eManager.createQuery("select c FROM News c WHERE c.NEWSID = :id",News.class);
return (News)query.setParameter("id", newsId).getSingleResult();
我得到了这个例外:
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和命名参数相同
Why does it happen? :id and named parameter are identical
我的实体课
@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查询中区分大小写,并且应使用与实体中出现的大小写完全相同的大小写形式.
That happens because News
entity does not have persistent attribute named NEWSID
. Names of the persistent attributes are case sensitive in JPQL queries and those should be written with exactly same case as they appear in entity.
因为实体具有名为newsId
的持久属性,所以该属性也应在查询中使用,而不是NEWSID
:
Because entity have persistent attribute named newsId
, that should also be used in query instead of NEWSID
:
select c FROM News c WHERE c.newsId = :id
这篇关于JPQL:状态字段路径无法解析为有效类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文