0

I would like to implement something that I would call a conditional insert using Hibernate. So let's say I have an entity named A which maps to the corresponding table A. Before persiting a new Row to the table I want't to check if a certain row is already present and only insert the new one if it isn't. I also have multiple Clients who concurrently write to table A.

In my opinion I have to lock the entire table A before doing the check to prevent concurrent access by many clients.

So my question is how I would do this in Hibernate. Is it possible. Or am I wrong and there is maybe a completely different solution.

Christian Hager
  • 468
  • 6
  • 22
  • Have you seen [this](http://stackoverflow.com/questions/3562105/jpa-create-if-not-exists-entity)? – mindas May 08 '13 at 16:42
  • Indeed I didn't. The Problem described in this post is very similar to mine but there is no real solution for the race conditions that can occur if I accessed by multiple vms concurrently. – Christian Hager May 10 '13 at 05:09

0 Answers0