(Just an observer here.) Sounds like--leaving JPA out of it for a moment--you must also be using pessimistic locking in the database, right? to ensure that this not-enforced-by-the-database constraint is holding?
If so, you may want to look into lock modes in JPA and issuing a find() first with a pessimistic lock, and, if that fails, then proceeding with the persist() call. Best, Laird On Tue, Jun 10, 2014 at 10:44 AM, Rupert Smith [via OpenJPA] < [email protected]> wrote: > On 10 June 2014 16:31, Kevin Sutter <[hidden email] > <http://user/SendEmail.jtp?type=node&node=7586814&i=0>> wrote: > > > I think you are just describing a unique constraint for a column (other > > than the primary key). > > > Sadly not, it isn't simply a question of putting a unique constraint on > some columns. As I pointed out, in some cases a duplicate is allowed, in > others it is not. I could just re-arrange the database design, but I don't > own the design it is something that has been given to me. > > Consider the case where the criteria to allow an insert to happen is some > arbitrary query, not just a unique constraint. This can be accomplished > with a WHERE NOT EXISTS (SELECT ... the arbitrary insertion condition). > How > can this be done with JPA/OpenJPA? > > Rupert > > > ------------------------------ > If you reply to this email, your message will be added to the discussion > below: > > http://openjpa.208410.n2.nabble.com/How-to-prevent-multiple-inserts-of-same-item-by-some-criteria-tp7586812p7586814.html > To start a new topic under OpenJPA Users, email > [email protected] > To unsubscribe from OpenJPA Users, click here > <http://openjpa.208410.n2.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=208411&code=bGpuZWxzb25AZ21haWwuY29tfDIwODQxMXw4OTk4MzY1OTI=> > . > NAML > <http://openjpa.208410.n2.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml> > -- http://about.me/lairdnelson -- View this message in context: http://openjpa.208410.n2.nabble.com/How-to-prevent-multiple-inserts-of-same-item-by-some-criteria-tp7586812p7586815.html Sent from the OpenJPA Users mailing list archive at Nabble.com.
