-->
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.  [ 5 posts ] 
Author Message
 Post subject: Mapping inheritence to the child.xml instead of parent.xml?
PostPosted: Tue Jul 18, 2006 5:09 am 
Newbie

Joined: Tue Jul 18, 2006 5:03 am
Posts: 3
Hibernate version: 3.0

I'm trying to create an 'addon' type structure, where I have a Parent.har containing a Parent.class and a Parent.hbm.xml.

Code:
package mypackage;

/**
* @hibernate.class
*  table = "parents"
*
*/
public class
Parent
{
    public
    Parent()
    {       
    }
   
    /**
     * @hibernate.id
     *     column = "id"
     *     type = "long"
     *     generator-class = "native"
     *
     * @return
     */
    public Long
    getID()
    {
        return theID;
    }
   
    public void
    setID(Long anID)
    {
        theID = anID;
    }
   
    private Long theID = null;


Code:
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping
>
    <class
        name="mypackage.Parent"
        table="parents"
    >

        <id
            name="ID"
            column="id"
            type="long"
        >
            <generator class="native">
            </generator>
        </id>
    </class>

</hibernate-mapping>



Now I wan to be able to add separate extending objects, which are placed in seperate har files, to the above mentioned ORM parent object. Something as simple as given below.

Code:
package mysecondpackage;

import mypackage.Parent;

/**
* ?????????????????
*/
public class
Child
extends Parent

    public   
    Child()
    {       
    }


The only problem is, that I want the Child.hbm.xml to declare the inheritence and not the Parent.hbm.xml. Although the hibernate docs say it's possible, I can't seem to get it working with polymophism working.

If someone knows how to realize this, please enlighten me :)
Also, can it only be done manually?... because I can't find any tags for Xdoclet that would allow it to be done automatically....


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 18, 2006 8:06 am 
Regular
Regular

Joined: Wed May 05, 2004 3:41 pm
Posts: 118
Location: New Jersey,USA
You can try something like this:

Code:
<hibernate-mapping package="com.hibernate.forums">
     <subclass name="ChildClass" extends="ParentClass" discriminator-value="D">
      <property
         name="Descriptions"
         column="DESCRIPTIONS"
         type="string"
         not-null="false"
         length="10"
      />
   </subclass>   
</hibernate-mapping>

Of course I'm assuming you are using "table per hierarchy" here. But you can do similar XML for the other strategies as well.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 18, 2006 8:25 am 
Newbie

Joined: Tue Jul 18, 2006 5:03 am
Posts: 3
I'll get to trying it.

You wouldn't happen to know how this can be fed to XDoclet so I don't have to put in the work manually, would you? :)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 18, 2006 8:44 am 
Regular
Regular

Joined: Wed May 05, 2004 3:41 pm
Posts: 118
Location: New Jersey,USA
I have'nt played around too much with XDoclet. But I think the mapping document is straight forward so I'll assume that the corresponding XDoclet tags in ChildClass should serve the purpose.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 31, 2006 4:46 am 
Newbie

Joined: Tue Jul 18, 2006 5:03 am
Posts: 3
Neither are there X-doclet tags available for this purpose as it is possible to declare anything but subclasses with discriminator values.... and seeing as I need to enforce not-null, I need joined subclasses ... which are impossible to declare outside of the 'parent xml mapping file'.

Does anyone have a golden solution to this .... one I overlooked.... please tell me.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

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.