我得到一個異常時,我試圖通過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