0

我想在我的数据库中保存一个成员。我注释了我的 id,例如:

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "id",unique=true, nullable = false)
private Integer id;

hbm.xml 的一部分:

<id name="id" type="native">
        <column name="ID" />
        <generator class="increment" />
    </id>

我试图手动添加 id...但不工作...我在这里做错了什么?

这是方法:

public Member save() throws ClassNotFoundException, HibernateException, SQLException, InstantiationException, IllegalAccessException {
    Member member=new Member();
    member.setName(this.name);
    member.setSurname(this.surname);
    member.setEmail(this.email);
    member.setUsername(this.username);
    member.setPassword(this.password);

    SessionFactory sf = HibernateUtil.getSessionFactory();
    Session session = sf.openSession();
    session.beginTransaction();

    session.save(member);


    session.getTransaction().commit();

    session.close();
4

0 回答 0