Hibernate envers: merge & saveOrUpdate

I am working on a spring-hibernate-envers application. After many search jobs finally work for me, but I still have a couple of questions.

  • I used saveOrUpdateto save or update objects. But when dealing with throwing a nonUniqueObject exception. So I used mergeinstead and it worked. Is it right to use merge for this? Does mergeinserts insert new objects for db?

  • I tried the following code:

entity=merge(entity);  
saveOrUpdate(entity);

That also worked. Is it correct? And also I am curious why saveOrUpdatenot throwing any errors now.

+3
source share
2 answers

Hibernate Reference says:

saveOrUpdate() :

  • , ,
  • , , , ,
  • , save() it
  • , , save() it
  • a , version - , , save() it
  • ()

merge() :

  • , ,
  • ,
  • ,

, saveOrUpdate(), , . merge().

entity=merge(entity);
saveOrUpdate(entity); 

, merge() , saveOrUpdate(), .

+10

saveOrUpdate: ( ), . , .

merge: Hibernate , . . , Detached Persistence. , "".

, . , .

0

All Articles