Search code examples
hibernatejpa-2.0named-query

JPA2 error validation : state field cannot be resolved


I have a error that I can not get rid of, but the code works in the same time.

@NamedQuery(name="getDocteur", query="SELECT d FROM Clinique cli, IN (cli.docteurs) AS d WHERE cli.clinique_ID=:clinique_ID AND d.docteur_ID=:docteur_ID")

the Error Eclipse give me is this :

The state field path 'd.docteur_ID' cannot be resolved to a valid type.

I got the same error with this query too

@NamedQuery(name="validUsername", query="SELECT u FROM Clinique cli, IN (cli.users) AS u WHERE cli.clinique_ID=:clinique_ID AND u.username=:username AND u.password=:password")



User.java 
...

@Column(name="PASSWORD", nullable=false)
    @NotNull
    @Size(min=8, max=8)
    private String password;



Docteur.java

package com.jerabi.model;

import java.io.Serializable;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

import java.util.ArrayList;
import java.util.List;


/**
 * The persistent class for the docteur database table.
 * 
 */
@Entity
@Table(name="Docteur",
        uniqueConstraints={@UniqueConstraint(columnNames={"clinique_Clinique_ID", "nom", "prenom"})}
)
public class Docteur implements Serializable {
    private static final long serialVersionUID = 1L;

@Id 
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="DOCTEUR_ID")
private Integer docteur_ID;

@Column(name="Nom", nullable=false)
@NotNull
@Size(min=1, max=40)
private String nom;

@Column(name="Prenom", nullable=false)
@NotNull
@Size(min=1, max=40)
private String prenom;

@ManyToOne(optional=false)
private Clinique clinique;

//bi-directional many-to-one association to Patient
@OneToMany(cascade={CascadeType.PERSIST, CascadeType.MERGE, CascadeType.DETACH}, orphanRemoval=false, mappedBy="docteur")
private List<Patient> patients;

public Docteur() {
    patients = new ArrayList<Patient>();
}

public Integer getDocteur_ID() {
    return this.docteur_ID;
}

public void setDocteur_ID(Integer docteurId) {
    this.docteur_ID = docteurId;
}

public String getNom() {
    return this.nom;
}

public void setNom(String nom) {
    this.nom = nom;
}

public String getPrenom() {
    return this.prenom;
}

public void setPrenom(String prenom) {
    this.prenom = prenom;
}

public List<Patient> getPatients() {
    return this.patients;
}

public void setPatients(List<Patient> patients) {
    this.patients = patients;
}

public Clinique getClinique() {
    return clinique;
}

public void setClinique(Clinique clinique) {
    this.clinique = clinique;
}

}

Solution

  • Try this query,

    SELECT d
    FROM Clinique cli JOIN cli.docteurs d
    WHERE cli.clinique_ID = :clinique_ID
    AND d.docteur_ID = :docteur_ID