I think you are just describing a unique constraint for a column (other than the primary key). Here's one reference in the OpenJPA documentation, but there are several references through out the documentation or other JPA-related documentation.
http://ci.apache.org/projects/openjpa/trunk/docbook/manual.html#jpa_overview_mapping_unq Kevin On Tue, Jun 10, 2014 at 9:44 AM, Rupert Smith <rupertlssm...@googlemail.com> wrote: > Hi, > > Is there a way to prevent JPA/OpenJPA from doing multiple inserts? > > I have a somewhat inconvenient database design, whereby some types held in > a table only allow a single instance to be created (other types do allow > it). This makes preventing multiple instances not so easy to achieve with > simple unique constraints. > > What I effectively want to do is something like this: > > INSERT INTO Applications (..., type) > VALUES (..., someType) > WHERE NOT EXISTS (SELECT FROM Applications WHERE type = someType) > > That is for some Applications where only a single instance is allowed for a > type, to prevent multiple instances from being inserted. > > Only answer I have found so far is: > > > http://www.quora.com/Relational-Databases/JPA-conditional-insertion-RDBMS-transactions-isolation > > But I cannot make sense of it. > > Thanks for your help. > > Rupert >