Does Hibernate support upsert/merge? In other words, automatically insert the record if it doesn't exist in the database and automatically update the record if it already does exist?
I have come across a scenario where this would come in handy. I have numerous threads which can potentially write to the same record in a table. If the record doesn't exist, it is supposed to insert. If it does exist, it is supposed to update. The problem is some of threads step on each other, so I get a constraint violation when some of the threads tries to insert at the "same time."
I could catch the contraint violation and force an update, but I was wondering if there was any way to make Hibernate manage it. Thanks!
|