Mahmoud Sabeh-Allah
Mahmoud Sabeh-Allah

Reputation: 21

Hibernate Duplicate values when inserting data

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();

Upvotes: 0

Views: 262

Answers (2)

Balaji Reddy
Balaji Reddy

Reputation: 5710

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

Upvotes: 0

Anand Kumar
Anand Kumar

Reputation: 165

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

Upvotes: 1

Related Questions