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: Multiple many to many mappings sharing one table.
PostPosted: Tue Jul 15, 2008 2:52 pm 
Newbie

Joined: Tue Jul 15, 2008 2:48 pm
Posts: 1
I have "Assessment", "Attachment" and "Control" tables. Assessment and Attachment are many to many with a join table. Same with Control and Attachment are many to many with a join table. To minimize the manual insert/delete, I am using cascade="all-delete-orphan". If I have a attachment, say doc1, linked to both assessment and control. How do I remove the link between Assessment and Attachment, but still keep the link between the Control and Attachment? I tried to remove the Attachment object from the Assessment.getAttachments() collection and then persist the Assessment object. I got the org.hibernate.exception.ConstraintViolationException error because Hibernate tries to delete the Attachment record, even though the attachment is till linked to the a control.

Assessment mapping:

<set
name="attachements"
lazy="true"
cascade="all-delete-orphan"
table="ASSESSMENT_PERIOD_ATTACHEMENT"
>
<meta attribute="field-description">
@hibernate.set
lazy="true"
cascade="none"
table="ASSESSMENT_PERIOD_ATTACHEMENT"

@hibernate.collection-key
column="ASSESSMENT_ID"
@hibernate.collection-key
column="PERIOD"

@hibernate.collection-many-to-many
class="com.gs.fw.sox404.rep.dto.Attachement"
column="DOCUMENT_ID"
@hibernate.collection-many-to-many
class="com.gs.fw.sox404.rep.dto.Attachement"
column="PERIOD"
</meta>
<key>
<column name="ASSESSMENT_ID" />
<column name="PERIOD" />
</key>
<many-to-many
class="com.gs.fw.sox404.rep.dto.Attachement"
>
<column name="DOCUMENT_ID" />
<formula>PERIOD</formula>
</many-to-many>
</set>

Control mapping:

<set
name="attachements"
lazy="true"
cascade="all-delete-orphan"
table="CONTROL_PERIOD_ATTACHEMENT"
>
<meta attribute="field-description">
@hibernate.set
lazy="true"
cascade="none"
table="CONTROL_PERIOD_ATTACHEMENT"

@hibernate.collection-key
column="CONTROL_INSTANCE_ID"
@hibernate.collection-key
column="PERIOD"

@hibernate.collection-many-to-many
class="com.gs.fw.sox404.rep.dto.Attachement"
column="DOCUMENT_ID"
@hibernate.collection-many-to-many
class="com.gs.fw.sox404.rep.dto.Attachement"
column="PERIOD"
</meta>
<key>
<column name="CONTROL_INSTANCE_ID" />
<column name="PERIOD" />
</key>
<many-to-many
class="com.gs.fw.sox404.rep.dto.Attachement"
>
<column name="DOCUMENT_ID" />
<formula>PERIOD</formula>
</many-to-many>
</set>

And the Attachment mapping:

<set
name="assessmentPeriods"
lazy="true"
cascade="none"
inverse="true"
table="ASSESSMENT_PERIOD_ATTACHEMENT"
>
<meta attribute="field-description">
@hibernate.set
lazy="true"
cascade="none"
table="ASSESSMENT_PERIOD_ATTACHEMENT"

@hibernate.collection-key
column="DOCUMENT_ID"
@hibernate.collection-key
column="PERIOD"

@hibernate.collection-many-to-many
class="com.gs.fw.sox404.rep.dto.AssessmentPeriod"
column="ASSESSMENT_ID"
@hibernate.collection-many-to-many
class="com.gs.fw.sox404.rep.dto.AssessmentPeriod"
column="PERIOD"
</meta>
<key>
<column name="DOCUMENT_ID" />
<column name="PERIOD" />
</key>
<many-to-many
class="com.gs.fw.sox404.rep.dto.AssessmentPeriod"
>
<column name="ASSESSMENT_ID" />
<formula>PERIOD</formula>
</many-to-many>
</set>
<set
name="controlInstancePeriods"
lazy="true"
cascade="none"
inverse="true"
table="CONTROL_PERIOD_ATTACHEMENT"
>
<meta attribute="field-description">
@hibernate.set
lazy="true"
cascade="none"
table="CONTROL_PERIOD_ATTACHEMENT"

@hibernate.collection-key
column="DOCUMENT_ID"
@hibernate.collection-key
column="PERIOD"

@hibernate.collection-many-to-many
class="com.gs.fw.sox404.rep.dto.ControlInstancePeriod"
column="CONTROL_INSTANCE_ID"
@hibernate.collection-many-to-many
class="com.gs.fw.sox404.rep.dto.ControlInstancePeriod"
column="PERIOD"
</meta>
<key>
<column name="DOCUMENT_ID" />
<column name="PERIOD" />
</key>
<many-to-many
class="com.gs.fw.sox404.rep.dto.ControlInstancePeriod"
>
<column name="CONTROL_INSTANCE_ID" />
<formula>PERIOD</formula>
</many-to-many>
</set>


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.