Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JPQL: Field path cannot be resolved to a collection type

Tags:

jpa

jpql

I'm trying to make a search on the date based on a list of possible dates the user can pick from. With a calendar I ask the user to input a date and then I want to get all the possible packets who have that date in their "data_possibile" list.

This is the query I'm using:

@NamedQuery(name="pacchettoPreconfigurato.findVendibileByData", query="SELECT p FROM PacchettoPreconfigurato p WHERE p.in_vendita=TRUE AND (:data) IN (p.date_possibili)")

Now, when I try to deploy the application in the logs of the server I get:

Exception Description: Problem compiling [SELECT p FROM PacchettoPreconfigurato p WHERE p.in_vendita=TRUE AND (:data) IN (p.date_possibili)]. [81, 97] The state field path 'p.date_possibili' cannot be resolved to a collection type.

This is how p.date_possibili is defined:

@OneToMany(orphanRemoval=true)
@JoinColumn(name="id_pp")
private List<DataPossibilePP> date_possibili;

where DataPossibilePP is:

@Entity
@IdClass(DataPossibilePPPK.class)
public class DataPossibilePP implements Serializable {     
    @Id
    private Integer id_pp;   
    @Id
    private Date data;
    private static final long serialVersionUID = 1L;
    /*standard getters and setters*/
}

I don't understand why I'm told the field is not a collection, even if it is defined as a list and Eclipse itself suggests me it in its autocomplete.

How could I write the query so that it compiles?

like image 867
GPhilo Avatar asked Jan 20 '14 11:01

GPhilo


1 Answers

The in operator can't be used on a collection. It's supposed to be used on a list of values passed as argument to the query, or on a subselect.

You're probably looking for the member of operator, which tests if some argument is a part of a collection:

select student from Student student where :course member of student.courses
like image 133
JB Nizet Avatar answered Oct 16 '22 14:10

JB Nizet