【求助】[hibernate]每运行一次程序,为何用session.save()会把表中的行替换而不是增加?

snowolf128 snowolf128 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
发现每运行一次程序,程序中的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>
...全文
评论 9
收藏 已收藏
分享
返回顶部
snowolf128
Java EE 67,535 成员 225,843 内容