【求助】[hibernate]每运行一次程序,为何用session.save()会把表中的行替换而不是增加?
发现每运行一次程序,程序中的session.save代码都会把原数据库表中的行清空,再插入;而不是生成identity,插入到最后。请问有啥解决办法?
console中的显示信息:
Hibernate: insert into Star (name, xxxx) values (?, xx)
select @@identity
程序代码:
Session session=HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
Star star = new Star();
star.setName("aa");
star.set...("aa");
session.save(star);
session.getTransaction().commit();
环境:hibernate3.1,sybase 12.5
maping:
<class name="Star">
<id name="id">
<generator class="native"/>
</id>
<property name="name" length="10" not-null="true"/>
<property name="age" length="4" not-null="false"/>
<property name="resume" length="1000" not-null="true"/>
<property name="sign" length="500" not-null="false"/>
<property name="phone" length="13" not-null="true"/>
<property name="imagePath" length="100" not-null="true"/>
</class>