且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

为什么每次运行我的应用程序时,Hibernate都会插入重复的记录?

更新时间:2023-10-23 08:18:46

saveOrUpdate()如果实体没有ID,则保存实体,如果已经有一个ID。你总是传递没有ID的实体,所以Hibernate创建实体。每一次。

saveOrUpdate() saves the entity if it doesn't have an ID, and updates it if it already has an ID. You always pass entities which don't have an ID, so Hibernate creates the entity. every time.

唯一标识一个实体的是它的ID。不是其名称,文字或任何其他属性。

The only thing that identifies an entity is its ID. Not its name, text, or whatever other attribute.