0

when inserting into the database using persist function in hibernate session

it sometimes duplicates rows , is it a problem with hibernate ?

currentSession.persist(cloudUser);
currentSession.flush();

tx.commit();
  • Try to gather logs of what Hibernate doing [as described here](http://stackoverflow.com/questions/1710476/print-query-string-in-hibernate-with-parameter-values). And provide here more information about what you exactly doing. Hibernate itself is fine in such trivial cases. – Alexey Andreev Nov 27 '13 at 08:35

2 Answers2

1

persist() method doesn't guarantee that the identifier value will be assigned to the persistent instance immediately, the assignment might happen at flush time.

Read more: http://javarevisited.blogspot.com/2012/09/difference-hibernate-save-vs-persist-and-saveOrUpdate.html#ixzz2lpDfeIh8

Anand Kumar
  • 145
  • 1
  • 3
  • 16
0

You have two methods to persist your object. save () and persist()... While taking decision ,ID generation strategy also should be taken into the consideration. Save method will fire insert query immediately but persist() will not..

Clcik Here

Community
  • 1
  • 1
Balaji Reddy
  • 5,576
  • 3
  • 36
  • 47