这是我的测试代码:
Employee emp = new Employee();
emp.setUsername("test");
emp.setPassword("test");
sf = new Configuration().configure().buildSessionFactory();
log.debug("SessionFactory created");
session = sf.openSession();
Transaction tx = session.getTransaction();
tx.begin();
log.debug("Saving Employee");
System.out.println(emp);
session.save(emp);
session.flush();
if(!tx.wasCommitted())
{
tx.commit();
log.debug("Employee saved");
}
这是我的员工班
@Entity
@Table(name = "EMPLOYEES")
public class Employee
{
@Id
@GenericGenerator(name="emp_id_sq", strategy="generator.EmployeeIdGenerator")
@GeneratedValue(generator="emp_id_sq")
@Column(name = "EMP_ID", unique = true, nullable = false)
private long id;
@Column(name = "USERNAME", unique = true, nullable = false)
private String username;
@Column(name = "PASSWORD", nullable = false)
private String password;
@OneToMany(mappedBy = "employee")
private Collection<Timecard> timecards;
我收到错误:org.hibernate.HibernateException:models.Employee 实例的标识符从 24 更改为 24
我不知道为什么会出现错误,但是当我尝试提交保存时会发生这种情况。