You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by Werewolf <ne...@hotmail.com> on 2010/05/04 10:20:03 UTC

ManyToMany relations violating unique constraints

Hi,
i am trying to build an API for my company, but i am facing problems:

my ERM looks like this:

InstanceITem http://n2.nabble.com/file/n5002254/ERM.png 

actually i am just trying to insert some elements of InstanceItem using
em.merge().
i get a unique constraint violation for Parameter. i have chosen ManyToMany
because i want to "recycle" some parameters, becaused i wanted to avoid
redundancy. so multiple referencings to the same parameter are possible and
very normal for a M2M relation.

All data sets are identified by business logic (unique key constraint). 
so i do something wrong when i use em.merge(instanceItem); ?
my mapping file and persistence.xml is appended.
http://n2.nabble.com/file/n5002254/orm_mysql_hierarchy.xml
orm_mysql_hierarchy.xml  http://n2.nabble.com/file/n5002254/persistence.xml
persistence.xml 

thanks for your help in advance

Gerald

-- 
View this message in context: http://openjpa.208410.n2.nabble.com/ManyToMany-relations-violating-unique-constraints-tp5002254p5002254.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Re: ManyToMany relations violating unique constraints

Posted by Pinaki Poddar <pp...@apache.org>.
Hi,
  Can you post the error? 
If business logic ensured that {P_TYPE_ID, P_VALUE_STRING} of Parameter are
unique combination then what exactly was the state of the Parameter instance
P that violated the unique constrain?
One possibility is during merge() operation, OpenJPA has wrongly judged the
persistent life-cycle state of a detached Parameter instance P, and tried to
re-insert P. But more data points are needed to diagnose what is going
wrong.



-----
Pinaki 
-- 
View this message in context: http://openjpa.208410.n2.nabble.com/ManyToMany-relations-violating-unique-constraints-tp5002254p5014509.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Re: ManyToMany relations violating unique constraints

Posted by Werewolf <ne...@hotmail.com>.
No, YP_PARAMETER_ID is the Primary Key and belongs to Database Logic.
the Unique Constraint consists of YP_PARAMETER_TYPE_ID and its belonging
value YP_PARAMETER_VALUE_STRING. in this combination the parameter is unique
by Business Logic.
-- 
View this message in context: http://openjpa.208410.n2.nabble.com/ManyToMany-relations-violating-unique-constraints-tp5002254p5013016.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Re: ManyToMany relations violating unique constraints

Posted by Pinaki Poddar <pp...@apache.org>.
Hi,
<entity class="com.adva.yp.api.model.YPParameterImpl"
metadata-complete="true">
  <table name="YP_PARAMETER" schema="yp">
     <unique-constraint>
        <column-name>YP_PARAMETER_TYPE_ID</column-name>
        <column-name>YP_PARAMETER_VALUE_STRING</column-name>
     </unique-constraint>
  </table>

  Should not the unique constraint on Parameter table be on Y_PARAMETER_ID
instead of YP_PARAMETER_TYPE_ID?


-----
Pinaki 
-- 
View this message in context: http://openjpa.208410.n2.nabble.com/ManyToMany-relations-violating-unique-constraints-tp5002254p5011595.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.