开发者

merge is used only for creating or updating?

If i use ex.merge(obj), now if in object obj i set the primary key to a value which is not present in database, will it create a new record or will it throw an exception?

for example

if obj with pk val = 19 doesnot exist in database,and i set
obj.setPk(20);
obj.setName("nm");

em.merge(obj)  // will this throw an exception or 开发者_运维百科create a new record?`enter code here`


It will create a new record:

  • if the entity is already in the persistence context (session), no action is taken, except for cascades

  • if the entity is detached, a copy (object') is returned, which is attached (managed)

  • if the entity is transient (new instance), it is saved and a persistent (and managed) copy is returned

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜