JOOQ与Hibernate的行为 [英] JOOQ Vs Hibernate behavior
问题描述
因为我们知道 Hibernate
有一个很好的特性 SaveOrUpdate 当我们传递任何对象到这个方法时,它知道数据会是 update
或新记录将被添加到数据库中。这个功能还可以在 JOOQ
中使用,或者在我的代码中,我必须处理这个问题?
As we know Hibernate
have a a very good feature SaveOrUpdate when we pass any object to this method it know data would be update
or new record will be added in database. Is this feature also available in JOOQ
Or in my code i have to handle this?
推荐答案
jOOQ也是如此。如果你改变记录的主键,它将使用 INSERT
,否则它将使用 UPDATE
。
jOOQ does the same. If you change the primary key of a record, then it will use INSERT
, otherwise, it will use UPDATE
.
事实上,当您从数据库读取记录时,调用 store()
会触发一个 UPDATE
就像你所期望的那样。如果你创建一个新记录,那么它将会是 INSERT
ed。
As it is, when you read a record from the database, then calling store()
will trigger an UPDATE
as you'd expect. If you create a new record, then it will be INSERT
ed.
在2.6中,这有点难克隆一个记录,然后要求jOOQ更新它(因为克隆会将主键设置为新实例,因此将其标记为新 - >插入)。
With 2.6, it's a bit hard to clone a record and then ask jOOQ to update it (since cloning will set the primary key in a new instance, hence marking it as "new" -> insert).
这篇关于JOOQ与Hibernate的行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!