-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: ConstraintViolationException - Identifier changed in update
PostPosted: Fri May 22, 2009 2:14 am 
Newbie

Joined: Thu May 21, 2009 11:29 pm
Posts: 1
Hi, I encountered a problem when I trying to update the object RFQ , Hibernate tends to update its collection BQMaster and trying to set and update the identifier of BQMaster.

The postgre log file:
2009-05-22 11:16:53 ERROR: duplicate key violates unique constraint "bq_masters_pkey"
2009-05-22 11:16:53 STATEMENT: update bq_masters set rfq_id=$1, id=$2 where id=$3


error in console:
Caused by: java.sql.BatchUpdateException: Batch entry 0 update bq_masters set rf
q_id=2, id=0 where id=49449 was aborted. Call getNextException to see the cause
.
at org.postgresql.jdbc2.AbstractJdbc2Statement$BatchResultHandler.handle
Error(AbstractJdbc2Statement.java:2392)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutor
Impl.java:1257)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.ja
va:334)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeBatch(AbstractJdbc
2Statement.java:2451)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.jav
a:58)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:
195)
... 32 more

It seems very weird as it tried to update the id of bq_masters. It should keep the id and update only the other fields.


Code:
Criteria crit = session.createCriteria(BQMaster.class);
crit.add(Restrictions.eq("project",project);
crit.setFirstResult(5);
crit.setMaxResult(2);
List bqMasters = crit.list();

RFQ rfq = (RFQ)session.get(RFQ.class, RFQId);
rfq.setBqMasters(bqMasters);
session.update(rfq);


hibernate mapping:
Code:
   <class name="RFQ" table="rfq">
      <id name="id" column="id">
         <generator class="native">
            <param name="sequence">rfq_id_seq</param>
         </generator>
      </id>
      
      <property name="reference" column="reference" />
      <property name="status" column="status" />
      <property name="created" column="created" />
      <property name="modified" column="modified" />
      
      <many-to-one name="project" class="Project" column="project_id" cascade="save-update" />
      
      <list name="subcons" table="rfq_subcons">
         <key column="rfq_id" />
         <list-index column="id"/>
         <many-to-many class="Subcon" column="subcon_id"/>
      </list>

      <list name="bqMasters">
         <key column="rfq_id" />
         <list-index column="id"/>
         <one-to-many class="BQMaster"/>
      </list>

   </class>


Code:
   <class name="BQMaster" table="bq_masters">
      <id name="id" column="id">
         <generator class="native">
            <param name="sequence">bq_masters_id_seq</param>
         </generator>
      </id>
      
      <property name="reference" column="reference" />
      <property name="description" column="description" />
      <property name="lod" column="lod" />
      <property name="uom" column="uom" />
      <property name="quantity" column="quantity" />
      <property name="parentId" column="parent_id" />
      <property name="groupId" column="group_id" />
      <property name="leaf" column="leaf" />
      <property name="active" column="active" />
      <property name="subcontract" column="subcontract" />
      <property name="created" column="created" />
      <property name="modified" column="modified" />
      
      <many-to-one name="project" class="Project" column="project_id" cascade="save-update" />

      <many-to-one name="page" class="Page" column="page_id" cascade="save-update" />
      
      <many-to-one name="rfq" class="RFQ" column="rfq_id" cascade="save-update" />
      
   </class>




Can anybody please give me some hint on solving this problem? Thanks in advance.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.