在这里我们来讨论四种主键生成器
1、increment
2、identiey
3、uuid
那么我们先来第一种:
@Test
public void testIncrement(){
//开启session连接
Session session=sessionFactory.openSession();
//开启事务
Transaction transaction=session.beginTransaction();
//新建对象
Person person=new Person();
person.setPname("willain");
//保存对象
session.save(person);
//提交事务及关闭连接
transaction.commit();
session.close();
}
在这里,我先要设置hibernate.cfg.x