【发布时间】:2016-03-22 03:52:57
【问题描述】:
我正在尝试触发 MySQL 的存储过程,在 MySQL 中存储过程工作正常,但是当我尝试从 Hibernate 触发时,它给出了异常。
org.hibernate.MappingException: Named query not known: GetEmployeeDetails
这是我的代码。
//Stored procedure
Query q = session.getNamedQuery("GetEmployeeDetails").setParameter("empId", 10);
List<?> result = q.list();
for(int i = 0; i < result.size(); i++) {
Employee e = (Employee)result.get(i);
System.out.println("Employee Name :"+e.getName());
}
我的 Employee 类是。
import javax.persistence.Entity;
import javax.persistence.Id;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
@Cache(usage = CacheConcurrencyStrategy.READ_ONLY)
@Entity
public class Employee {
@Id
private int id;
private String name;
public Employee() {
}
public Employee(int id, String name) {
super();
this.id = id;
this.name = name;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
我的存储过程
CREATE DEFINER=`root`@`localhost` PROCEDURE `GetEmployeeDetails`(empid varchar(20))
BEGIN
select * from employee where id=empid;
END
【问题讨论】:
标签: java mysql hibernate stored-procedures