Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

org.hibernate.QueryException: could not resolve property

807580Jan 20 2010 — edited Jan 20 2010
Hello, I have a problem with a query using JBoss.

I have a session bean with this method:
@Stateless
public class VisitBean implements VisitBeanRemote {
	
	@PersistenceContext(unitName="MECSDB") private EntityManager manager;

	public int addHospitalization(Hospitalization hosp) {
		
		Query query = manager.createQuery("from Hospitalization h where h.PatientID=:PID");
		query.setParameter("PID", hosp.getPatient().getSSN());
		if (query.getResultList().size()>0) return -1;
		else {
			manager.persist(hosp);
			return hosp.getId();
		}
	}
}
Where the entity Hospitalization is:
import javax.persistence.*;

@SuppressWarnings("serial")
@Entity
@Table(name="Hospitalization")
public class Hospitalization implements java.io.Serializable {
	
	private int Id;
	private Patient patient;
	private String diagnosis;
	private String therapy;
	
	@Id
	@GeneratedValue
	@Column(name="ID")
	public int getId() {
		return Id;
	}
	public void setId(int id) {
		Id = id;
	}
	
	@OneToOne
	@JoinColumn(name="PatientID")
	public Patient getPatient() {
		return patient;
	}
	public void setPatient(Patient patient) {
		this.patient = patient;
	}
	
	@Column(name="Diagnosis")
	public String getDiagnosis() {
		return diagnosis;
	}
	public void setDiagnosis(String diagnosis) {
		this.diagnosis = diagnosis;
	}
	
	@Column(name="Therapy")
	public String getTherapy() {
		return therapy;
	}
	public void setTherapy(String therapy) {
		this.therapy = therapy;
	}
	
}
And the entity Patient is:
import javax.persistence.*;

@SuppressWarnings("serial")
@Entity
@Table(name="Patient")
public class Patient implements java.io.Serializable {
	
	private long SSN;
	private String name;
	private String surname;
	private int age;
	private String familydoctor;
	
	@Id
	@Column(name="SSN")
	public long getSSN() {
		return SSN;
	}
	public void setSSN(long ssn) {
		this.SSN = ssn;
	}
	
	@Column(name="Name")
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	
	@Column(name="Surname")
	public String getSurname() {
		return surname;
	}
	public void setSurname(String surname) {
		this.surname = surname;
	}
	
	@Column(name="Age")
	public int getAge() {
		return age;
	}
	public void setAge(int age) {
		this.age = age;
	}
	
	@Column(name="FamilyDoctor")
	public String getFamilydoctor() {
		return familydoctor;
	}
	public void setFamilydoctor(String familydoctor) {
		this.familydoctor = familydoctor;
	}

}
But when I call the method addHospitalization from my program i receive this exception:
org.hibernate.QueryException: could not resolve property: PatientID of: domain.Hospitalization [from domain.Hospitalization h where h.PatientID=:PID]

Can anyone help me to understand how to correct the problem?
Thanks in advance.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 17 2010
Added on Jan 20 2010
4 comments
9,828 views