-->
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: Two sets containing objects of same class
PostPosted: Wed Jul 28, 2004 4:36 am 
Newbie

Joined: Wed Feb 11, 2004 5:08 am
Posts: 14
Hi all,

I have a question about how to map a situation where I have two sets (one-to-many relations) from one class to another.

I have a class Test to which Remarks can be attached. Remarks can be produced either by the user or by the system itself. I want to keep the Remarks separated since they are handled in different ways in the business logic. Simplest way to achieve this I think is to have two Sets of Remarks in my Test object.

Now the problem rises since according to the documentation "An instance of the contained entity class may not belong to more than one instance of the collection" when using one-to-many mappings.

So after reading that I tried to create a link table between the classes using many-to-many relation and I almost succeeded with these mappings int Test.hbm.xml:
Code:
        <!-- User Remarks -->
        <set name="userRemarks" sort="natural" table="test_user_remark_link" cascade="all">
            <key column="test_id"/>
            <many-to-many class="HibernateRemark" column="remark_id"/>
        </set>
        <!-- System Remarks -->
        <set name="systemRemarks" sort="natural" table="test_system_remark_link" cascade="all">
            <key column="test_id"/>
            <many-to-many class="HibernateRemark" column="remark_id"/>
        </set>

The problem with previous mappings is the cascading. When I remove Remarks from the Sets the orphan instances are left to the DB. I tried to change the cascading to "all-delete-orphan" and that leads to me getting exceptions about failing foreign key constants.

What would be the preferred solution to map this kind of situation with Hibernate?


Sincerely,

Jouni Hartikainen


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.