我得到一个异常时,我试图通过Hibernate持久层来保存一些数据,例外的是Hibernate |标识符生成异常
org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save(): hbm.Employee
public void saveEmployee(Employee empValue) {
Session session = null;
Transaction tx = null;
session = HibernateSessionFactory.getSession();
tx = session.beginTransaction();
Employee emp;
if (empValue.getEmpcode() != null) {
emp = (Employee) session.get(Employee.class, empValue.getEmpcode());
if (emp != null) {
System.out.println("Test");
emp.setEmpcode(empValue.getEmpcode());
emp.setDepartment(createDepartment("DEEE"));
emp.setEmpfname(empValue.getEmpfname());
emp.setEmplname(empValue.getEmplname());
emp.setEmpdob(empValue.getEmpdob());
emp.setEmpstatus(empValue.getEmpstatus());
emp.setEmptelno(empValue.getEmptelno());
emp.setAuditfield(empValue.getAuditfield());
session.update(emp);
}
} else
{
emp = new Employee();
emp.setEmpcode(empValue.getEmpcode());
emp.setDepartment(createDepartment("DEEE"));
emp.setEmpfname(empValue.getEmpfname());
emp.setEmplname(empValue.getEmplname());
emp.setEmpdob(empValue.getEmpdob());
emp.setEmpstatus(empValue.getEmpstatus());
emp.setEmptelno(empValue.getEmptelno());
emp.setAuditfield(empValue.getAuditfield());
session.save(emp);
}
tx.commit();
}
,你可以看到在类内得到适当的地方分配的,我很困惑例外情况,期待一些帮助..
设置为类.hbm文件 – Switch 2010-06-23 11:14:48
@MMRUser你能澄清哪个字段被标记为在映射的“ID” =“分配”? – 2010-06-23 11:52:38
empCode被标记为ID – Switch 2010-06-23 12:37:58