//设置主键自增
@Id
@Column(name = "RecordId", unique = true, nullable = false)
@GeneratedValue(strategy = GenerationType.AUTO)
//允许主键自动增长
使用hibernateSessionFactory获取session插入数据.
public void insertRecord(VistorRecord v) {
session = HibernateSessionFactory.getSession();
tran = session.beginTransaction();
session.save(v);
tran.commit();
HibernateSessionFactory.closeSession();
}
//获取数据库记录条数
public int getVisitorNum() {
session = HibernateSessionFactory.getSession();
String hql = "select count(*) from VistorRecord v";
long res = (long) (session.createQuery(hql).uniqueResult());
HibernateSessionFactory.closeSession();
return (int)res;
}