openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ljnelson <>
Subject Re: How to prevent multiple inserts of same item (by some criteria)
Date Tue, 10 Jun 2014 17:50:03 GMT
(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.


On Tue, Jun 10, 2014 at 10:44 AM, Rupert Smith [via OpenJPA] <> 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:
>  To start a new topic under OpenJPA Users, email
> To unsubscribe from OpenJPA Users, click here
> <>
> .
> <>


View this message in context:
Sent from the OpenJPA Users mailing list archive at
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message