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.  [ 4 posts ] 
Author Message
 Post subject: Inheritance with an interface using XDoclet
PostPosted: Mon Feb 16, 2004 1:54 pm 
Beginner
Beginner

Joined: Tue Jan 27, 2004 2:14 pm
Posts: 40
Location: Atlanta, GA, USA
I'm trying to do a test of the inheritance example in chapter 16.1 in the hibernate_reference.pdf. The example has an interface Payment with various subclasses. It uses the table-per-hierarchy mapping.

I'm trying to get the same result using XDoclet and the following test classes...

Interface IDog - XDoclet -
Code:
@hibernate.class table="Dog"
@hibernate.discriminator column="subclass" type="character"

@hibernate.id generator-class="native" type="int" column="Dog_ID" unsaved-value="0"

@hibernate.property column="Name" type="string" length="50" not-null="true" unique="false"

Class Poodle implements IDog - XDoclet -
Code:
@hibernate.subclass discriminator-value="P"

Class Boxer implements IDog - XDoclet -
Code:
@hibernate.subclass discriminator-value="B"


The XML that is generated from the XDoclet....

Code:
<class
        name="com.matrix.bo.IDog"
        table="Dog"
        dynamic-update="false"
        dynamic-insert="false"
    >

        <id
            name="id"
            column="Dog_ID"
            type="int"
            unsaved-value="0"
        >
            <generator class="native">
            </generator>
        </id>

        <discriminator
            column="subclass"
            type="character"
        />
       
        <property
            name="name"
            type="string"
            update="true"
            insert="true"
            column="Name"
            length="50"
            not-null="true"
            unique="false"
        />
       
    </class>


Notice that is is missing the <subclass> tags.
Question 1.) Is there something wrong with my XDoclet? Does XDoclet not support this feature?

Since this didn't look correct, I went ahead and manually added the needed <subclass> tags to the IDog.hbm.xml file.

Code:
<subclass
            name="com.matrix.bo.Poodle"
            dynamic-update="false"
            dynamic-insert="false"
            discriminator-value="P"
        >
</subclass>

<subclass
            name="com.matrix.bo.Boxer"
            dynamic-update="false"
            dynamic-insert="false"
            discriminator-value="B"
        >
</subclass>


When I tried a simple test to insert a Poodle and a Boxer....

Code:
session = sf.openSession();
tx = session.beginTransaction();

IDog poodle = new Poodle();
poodle.setColor("white");
poodle.setName("Fluffy");

IDog boxer = new Boxer();
boxer.setColor("brown");
boxer.setName("Rocco");

tx.commit();

...I got the following error. MappingException Could not format discriminator value to SQL string

Question 2.) What does this error message mean? My xml looks like the example in chapter 16.1, I don't see what I'm missing.

Thanks in advance for any help!


Top
 Profile  
 
 Post subject: Inheritance with an interface using XDoclet
PostPosted: Mon Feb 16, 2004 4:38 pm 
Beginner
Beginner

Joined: Tue Jan 27, 2004 2:14 pm
Posts: 40
Location: Atlanta, GA, USA
This is what I discovered....

I had to add a discriminator to my Interface to get this to work. The documentation in chapter 16.1 should probably be updated to include the discriminator if it is necessary to do so.

Code:
<class
        name="com.matrix.bo.IDog"
        table="Dog"
        dynamic-update="false"
        dynamic-insert="false"
        discriminator-value="I"
    >


I still can't get the <subclass> tags into the IDog.hbm.xml file using XDoclet, so I added a merge file that contains those mappings.

Is there a way to do this with XDoclet, to avoid using the merge directory?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 17, 2004 8:50 am 
Newbie

Joined: Tue Aug 26, 2003 12:31 pm
Posts: 14
The discriminator in the interface seems to be a stub and should never be used when persisting your concrete objects. However, the documentation in 16.1 does suggest that you do not need one. Can anyone else confirm if you need the discriminator on an interface?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 17, 2004 2:55 pm 
Newbie

Joined: Tue Aug 26, 2003 12:31 pm
Posts: 14
When using XDoclet tags with Hibernate where you have an interface and multiple subclasses you cannot specify which interface the subclass is using. It would be nice if you could specify the superclass implementation in the tag like this:

@hibernate.subclass superClass="InterfaceName"

so that you would not need a merge directory to insert the mappings. The superClass attribute could default to whatever the subclass extends or be overridden by the superClass attribute for the interface name. You can use an abstract superclass to get around this but you lose the interface.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.