我在hibernate中使用注释进行命名查询。我有两个类,一个POJO类和一个主类。POJO类如下
@NamedQuery(
name="findEmployeeName",
query="select * from employee "
)
@Entity
@Table(name="employee")
public class Employeenam {
public String tostring(){return id+" " +name+ " " +salary+ " " +job;}
@Id
@GeneratedValue
@Column(name="id")
int id;
@Column(name="name")
String name;
@Column(name="salary")
int salary;
@Column(name="job")
String job;
public int setempId(){
return id;
}
public void getempId(int Id){
this.id=Id;
}
public String setempName(){
return name;
}
public void getempName(String Name){
this.name=Name;
}
public int getempSalary(){
return salary;
}
public void setempSalary(int Salary){
this.salary=Salary;
}
public String setempJob(){
return job;
}
public void getempJob(String Job){
this.job=Job;
}
}
and the main class as follows
public class FetchData{
public static void main(String[] args){
Configuration configuration=new Configuration();
configuration.configure("hibernate.cfg.xml");
SessionFactory sfactory=configuration.buildSessionFactory();
Session session=sfactory.openSession();
Query query=session.getNamedQuery("findEmployeeName");
query.setString("name", "dfdsf");
query.setInteger("id", 34);
query.setInteger("salary", 3543);
query.setString("job", "dfgere");
session.close();
}
}
当我尝试运行此 iam 时出现以下错误
Exception in thread "main" org.hibernate.HibernateException:
Errors in named queries: findEmployeeName
谁能告诉我哪里出错了??我对休眠有点陌生..所以请原谅我任何明显的错误....