Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JPQL: The state field path cannot be resolved to a valid type

Tags:

jpql

I can't make this query work:

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

and I got this 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]. 

Why does it happen? :id and named parameter are identical

EDIT: my entity class

@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 
like image 897
DeadKennedy Avatar asked Nov 18 '13 20:11

DeadKennedy


1 Answers

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.

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
like image 50
Mikko Maunu Avatar answered Apr 28 '23 13:04

Mikko Maunu