-->
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: saveOrUpdate(), or cascade, causes a unique key violation
PostPosted: Thu Jul 01, 2004 10:02 am 
Newbie

Joined: Wed Jun 30, 2004 12:01 pm
Posts: 3
saveOrUpdate(), or cascade, just creates new rows for old instances (or causes a unique key violation)!

The faqs says

For a composite identifier, you should simply specify unsaved-value. In the second case, you can't use saveOrUpdate(). You should explicitly call save() or update() on a case-by-case basis, use Interceptor.isUnsaved in Hibernate2, or use version unsavec-value in Hibernate 2.1.


Does anyone have a example how to implement this

in stepState mapping file I have he following
.. should i chjange from cascade="all" to cascade="save-update" ?
<set
name="contents"
lazy="false"
inverse="true" cascade="all"
>
<meta attribute="field-description">
@hibernate.set
lazy="false"
inverse="true"

@hibernate.collection-key
column="CON_GROUP_ID"
@hibernate.collection-key
column="CON_WRK_SESSION_ID"
@hibernate.collection-key
column="CON_STEP_ID"

@hibernate.collection-one-to-many
class="com.test.groupstate.hibernate.Content"
</meta>
<key>
<column name="CON_STEP_ID" />
<column name="CON_WRK_SESSION_ID" />

<column name="CON_GROUP_ID" />
</key>
<one-to-many
class="com.test.groupstate.hibernate.Content"
/>

</set>

below is content table mapping
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >

<hibernate-mapping>

<class
name="com.testgroupstate.hibernate.Content"
table="CBMCON00"
>
<meta attribute="class-description" inherit="false">
@hibernate.class
table="CBMCON00"
</meta>

<composite-id name="contentPK"
class="com.test.groupstate.hibernate.ContentPK" unsaved-value="any">
<meta attribute="class-description" inherit="false">
@hibernate.id
generator-class="assigned"

</meta>
<key-property
name="contentTypeCode"
column="CON_CNTNT_TYPE_CDE"
type="java.lang.Integer"
length="5"
>
<meta attribute="field-description">
@hibernate.property
column="CON_CNTNT_TYPE_CDE"
length="5"
</meta>
</key-property>
<!-- bi-directional many-to-one association to Cbmsts00 -->
<key-many-to-one
name="stepState"
class="com.test.groupstate.hibernate.StepState"
>
<meta attribute="field-description">
@hibernate.many-to-one
column="CON_GROUP_ID""
</meta>
<meta attribute="field-description">
@hibernate.many-to-one
column="CON_WRK_SESSION_ID""
</meta>
<meta attribute="field-description">
@hibernate.many-to-one
column="CON_STEP_ID""
</meta>
<column name="CON_GROUP_ID" />

<column name="CON_WRK_SESSION_ID" />
<column name="CON_STEP_ID" />

</key-many-to-one>
</composite-id>
<!--
<timestamp column="CON_INSERT_TMS" name="insertTms" unsaved-value="null">
</timestamp>
-->

<property
name="contentObj"
type="java.lang.String"
column="CON_CNTNT_OBJ"
not-null="true"
length="100"
>
<meta attribute="field-description">
@hibernate.property
column="CON_CNTNT_OBJ"
length="100"
not-null="true"
</meta>
</property>


<property
name="insertTms"
type="timestamp"
column="CON_INSERT_TMS"
not-null="true"
length="26"
>

<meta attribute="field-description">
@hibernate.property
column="CON_INSERT_TMS"
length="26"
not-null="true"
</meta>
</property>




<!-- associations -->

</class>
</hibernate-mapping>


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.