Hibernate Exception:x实例的标识符被更改

时间:2013-08-24 18:54:05

标签: java hibernate

这是我的测试代码:

        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

我不知道为什么我收到错误,但是当我尝试提交保存时会发生错误。

0 个答案:

没有答案