-->
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: many-to-any?
PostPosted: Wed Mar 02, 2005 6:18 pm 
Newbie

Joined: Wed Mar 02, 2005 5:40 pm
Posts: 1
Hibernate version: 2.1.8

Name and version of the database you are using: HSQLDB 1.7.3.3

Hi, I know this question has been asked dozens of times here and elsewhere, but no direct answer seems to have been given and I've been searching for days. RTFM is certainly fair enough except that in this case there is no coverage of the issue in the manual (I have read section 6.10, but it doesn't help).

The issue is how to map a typical parent/child relationship, where the parent can be one of several unrelated classes. Simple example:

Code:
public class ParentA {
    String id;
    Set children;
    ...
}

public class ParentB {
    String id;
    Set children;
}

public class Child {
    String id;
    Object parent;
    ...
}


This is what I would have done, but it won't validate against the hibernate-mapping DTD, so it's obviously wrong.

Mapping documents:

Code:
<hibernate-mapping>
    <class name="ParentA" table="PARENTS_A">

        <id name="id" column="id" type="string" unsaved-value="null">
            <generator class="uuid.hex"/>
        </id>

        <set name="children" inverse="true" cascade="all-delete-orphan">
            <key column="parent_id"/>
            <one-to-many class="Child"/>
        </set>
        ...
    </class>
</hibernate-mapping>

<hibernate-mapping>
    <class name="ParentB" table="PARENTS_B">

        <id name="id" column="id" type="string" unsaved-value="null">
            <generator class="uuid.hex"/>
        </id>

        <set name="children" inverse="true" cascade="all-delete-orphan">
            <key column="parent_id"/>
            <one-to-many class="Child"/>
        </set>
        ...
    </class>
</hibernate-mapping>

<hibernate-mapping>
    <class name="Child" table="CHILDREN">

        <id name="id" column="id" type="string" unsaved-value="null">
            <generator class="uuid.hex"/>
        </id>

        <many-to-any id-type="string">
            <column name="parent_class"/>
            <column name="parent_id"/>
        </many-to-any>
        ...
    </class>
</hibernate-mapping>


According to the DTD, this is not the way to use many-to-any, but I cannot find any examples (on the site, in the manual, in the forums, or in two different books) of how it is actually done. Does anyone have an example handy of how to solve this very common problem?


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.