-->
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: Mapping problem with subclasses...
PostPosted: Tue Jan 04, 2005 7:28 am 
Beginner
Beginner

Joined: Tue May 11, 2004 10:40 am
Posts: 37
Location: Belgium
Hibernate version: Latest version of Hibernate.


I have the following 'uml' scheme:

----
//Root class.
abstract class SyntaxComponent
private String name;

----
//Subclass of SyntaxComponent
class Rule extends SyntaxComponent
private Operation op;

----
//Abstract Subclass of SyntaxComponent
abstract class Term extends SyntaxComponent

----
//Abstract Subclass of SyntaxComponent
abstract class Operation extends SyntaxComponent

----
//Subclass of Operation
class ComparisonOp extends Operation
private Term leftTerm;
private Term rightTerm;

----
//Subclass of Term
class Var extends Term

----

The problem is that I want to have one-to-one associations with subclasses from the same root. I have the following mapping: (wich doesn't give any problems):
I use the "Table per subclass" strategy...
Code:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
        "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<!-- @author Stijn Deroo-Van Maele -->
<!-- SyntaxComponent.hbm.xml -->
<!-- ORM mapping for 'SyntaxComponent' class -->

<hibernate-mapping>
   
    <class
        name="syntaxtree.SyntaxComponent"
        table="SYNTAX_COMPONENT">
       
        <id
            name="id"
            column="SYNTAX_COMPONENT_ID"
            type="long">
            <generator class="native"/>
        </id>       

        <property
            name="name"
            column="NAME"
            not-null="false"
            unique="false"
            type="string"/>
           
        <joined-subclass
         name="syntaxtree.Rule"
         table="RULE">
         <key column="RULE_ID"/>


         <many-to-one
             name="[color=red]operation[/color]"
             class="syntaxtree.Operation"
             column="OPERATION_ID"
             cascade="all"
             unique="true"/>   
         </joined-subclass>   


        <joined-subclass
         name="syntaxtree.Operation"
         table="OPERATION">
         <key column="OPERATION_ID"/>
         <property
             name="operatorType"
             column="OPERATOR_TYPE"
             type="string"
         />

            <joined-subclass
                name="syntaxtree.ComparisonOp"
                table="COMPARISON_OP">
                <key column="COMPARISON_OP_ID"/>
                <one-to-one name="leftTerm" class="syntaxtree.Term"/>
                <one-to-one name="rightTerm" class="syntaxtree.Term"/>
            </joined-subclass>           
                
      </joined-subclass>          
        <joined-subclass
         name="syntaxtree.Term"
         table="TERM">
         <key column="TERM_ID"/>
         <joined-subclass
            name="syntaxtree.Var"
            table="VAR">
            <key column="VAR_ID"/>
         </joined-subclass>   
        </joined-subclass>                                                                      
    </class>
</hibernate-mapping>



What's wrong? Hibernate won't store a rule, with an Operation member value. There are no faults, but in the database, nothing is filled in, only in the Rule table. (store(new Rule(new Operation))).

Is it possible to map everyting in one file like this above, or do I have to make different mapping files also for class Operation. And how do I declare it to be a subtype of SyntaxComponent?


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.