我正在使用以下bean类
package com.hibernatemappingfile;
import java.io.Serializable;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.Table;
@Entity
@Table(name="SKILL_SET")
public class SkillSet implements Serializable{
@Id
@Column(name="ID")
@GeneratedValue(strategy=GenerationType.AUTO)
private String id;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
@Column(name="COMPUTER_SKILLS")
private String computer_skills;
@Column(name="TRAININGS_ATTENDED")
private String trainings_attended;
@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "USER_ID")
private EmployeeMaster employee;
public EmployeeMaster getEmployee() {
return employee;
}
public void setEmployee(EmployeeMaster employee) {
this.employee = employee;
}
public String getComputer_skills() {
return computer_skills;
}
public void setComputer_skills(String computer_skills) {
this.computer_skills = computer_skills;
}
public String getTrainings_attended() {
return trainings_attended;
}
public void setTrainings_attended(String trainings_attended) {
this.trainings_attended = trainings_attended;
}
}
我的hql查询是
SELECT t1.trainings_attended,t2.workingstatus
FROM SkillSet t1, EmployeeStatus t2,EmployeeMaster em
WHERE t1.trainings_attended=:trainings_attended AND t1.USER_ID = t2.USER_ID
但我得到以下异常
SEVERE: Servlet.service() for servlet [sdnext] in context with path [/sdnext] threw exception [Request processing failed; nested exception is org.hibernate.QueryException: could not resolve property: USER_ID of: com.vrnda.hibernatemappingfile.SkillSet [SELECT t1.trainings_attended,t2.workingstatus FROM com.vrnda.hibernatemappingfile.SkillSet t1, com.vrnda.hibernatemappingfile.EmployeeStatus t2,com.vrnda.hibernatemappingfile.EmployeeMaster em WHERE t1.trainings_attended=:trainings_attended AND t1.USER_ID = t2.USER_ID]] with root cause
org.hibernate.QueryException: could not resolve property: USER_ID of: com.vrnda.hibernatemappingfile.SkillSet [SELECT t1.trainings_attended,t2.workingstatus FROM com.vrnda.hibernatemappingfile.SkillSet t1, com.vrnda.hibernatemappingfile.EmployeeStatus t2,com.vrnda.hibernatemappingfile.EmployeeMaster em WHERE t1.trainings_attended=:trainings_attended AND t1.USER_ID = t2.USER_ID]
如何在select statement.i中获取skillset表的user_id已尝试使用t1.em.USER_ID但无法正常工作。
答案 0 :(得分:1)
尝试JOIN t1.employee employee
,然后您就可以访问employee.user_id