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: A challenge. How best to associate classes to themselves?
PostPosted: Sat Mar 31, 2007 6:40 pm 
Newbie

Joined: Tue Dec 12, 2006 6:35 pm
Posts: 19
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:

Hibernate 3.2.2

Mapping documents:


<class name="ContentItem" table="CMS_ContentItem">
<cache usage="read-write"/>
<id name="id" column="id" type="integer" unsaved-value="0">
<generator class="native"/>
</id>
<property name="title"/>
<property name="description" type="text"/>

<set name="outboundLinks" table="CMS_ContentItem_ContentItem" cascade="none" >
<cache usage="read-write"/>
<key column="id"/>
<many-to-many column="link_id" class="ContentItem"/>
</set>

<set name="inboundLinks" table="CMS_ContentItem_ContentItem" cascade="none" inverse="true">
<cache usage="read-write"/>
<key column="link_id"/>
<many-to-many column="id" class="ContentItem"/>
</set>
</class>

Code between sessionFactory.openSession() and session.close():

hibernateTemplate.delete(contentItem);


Name and version of the database you are using:

MySQL 5.0.5

Debug level Hibernate log excerpt:

Integrity Constraint Violation



So here is the challenge:

I am writing a content management system and allowing users to link content together.

The problem is when I attempt to delete the object only that objects outbound links are being deleted.

After Hibernate deletes the objects outbound links it fails on an integrity constraint because other objects might still have outbound links pointing to it (represented as the invest inbound links collection).

What is the best way of dealing with this type of association?


Can hibernate handle this type of association where a primary key can appear in either column of the composite table?

Thanks

_________________
_________________________
http://www.joshandfriends.com.au

Dance Music | Events | DJs


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.