Hello,
I think that my problem is more DB in nature, but maybe it's a good place to ask. I would like to add a new entity only if it doesn't exist (I have some unique constraints).
So I can:
1. Add the entity, and wait for a possible exception when I flush() the session - but then the whole transaction will be rolled back.
2. First do a select and only if nothing is found, add the entity - but this has problems with concurrent access (two threads checking at the same time that the entity does not exist, and trying to add it - one gets an exception).
Is there any way to do this properly (and in Hibernate), without setting the db isolation level to serializable?
--
Regards,
Adam Warski
|