-->
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.  [ 3 posts ] 
Author Message
 Post subject: Inheritance and polymorphic associations
PostPosted: Sat Jan 08, 2005 3:29 pm 
Newbie

Joined: Sat Jan 08, 2005 2:23 pm
Posts: 3
Hello,

here the specifications of the problem:

Hibernate version: hibernate-2.1.7c

Name of the database you are using: PointBase

* Class hierarchy:

- Java code:

Abstract class: abstract class SyntaxTreeComponent
Abstract class: abstract class Rule extends SyntaxTreeComponent
Concrete class: class ConditionalRule extends Rule
Abstract class: abstract class Operation extends SyntaxTreeComponent
Concrete class: class ComparisonOp extends Operation

- Graphical representation ('<-' = inherits):

Code:

(abstract) SyntaxTreeComponent <-  (abstract) Rule <- ConditionalRule
                               <-  (abstract) Operation <-  ComparisonOp


* Polymorphic association:

A conditional rule has an (abstract) operation.

* Mapping files:

Used the 'table per subclass' strategy (reason: polymofism).

- SyntaxTreeComponent.hbm.xml:

Code:
<hibernate-mapping>   
   <class
       name="SyntaxTreeComponent"
       table="SYNTAX_TREE_COMPONENT">
       <id
          name="id"
          column="SYNTAX_COMPONENT_ID"
          type="long">
          <generator class="native"/>
       </id>                                                                         
   </class>
</hibernate-mapping>


- Operation.hbm.xml (Operation+ComparisonOp):

Code:
   
<hibernate-mapping>
   <joined-subclass
       name="Operation"
       extends="SyntaxTreeComponent"
       table="OPERATION">
       <key column="OPERATION_ID"/>
       <joined-subclass
            name="ComparisonOp"
            table="COMPARISON_OP">
           <key column="COMPARISON_OP_ID"/>
       </joined-subclass>
   </joined-subclass>
</hibernate-mapping>


- Rule.hbm.xml (Rule+ConditionRule) CONTAINS THE PROBLEM ASSOCIATION:

Code:
   
<hibernate-mapping>
   <joined-subclass
        name="Rule"
        extends="SyntaxTreeComponent"
        table="RULE">
        <key column="RULE_ID"/>
        <joined-subclass
            name="ConditionalRule"
            table="CONDITIONAL_RULE">
            <key column="CONDITIONAL_RULE_ID"/>
            <many-to-one
                 name="operation"
                 class="Operation"
                 column="OPERATION_ID"
                 cascade="save-update"/>
         </joined-subclass>
    </joined-subclass>
</hibernate-mapping>


* Error messages:

Code:
Code:

   Rule rule = new ConditionalRule(new ComparisonOp()); 
    ...
   session.save(rule);
    ...

Error:
Code:
JDBCExceptionReporter:58 - Referential Integrity Violation. CONDITIONAL_RULE references OPERATION
...
Caused by: java.sql.SQLException: Referential Integrity Violation. CONDITIONAL_RULE references OPERATION


Thanks in advance,
Johan


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 08, 2005 4:22 pm 
Newbie

Joined: Sat Jan 08, 2005 2:23 pm
Posts: 3
Here some extra information about the SQL statements:

Code:
create table SYNTAX_TREE_COMPONENT (
   SYNTAX_COMPONENT_ID bigint not null,
   primary key (SYNTAX_COMPONENT_ID)
)
create table CONDITIONAL_RULE (
   CONDITIONAL_RULE_ID bigint not null,
   OPERATION_ID bigint,
   primary key (CONDITIONAL_RULE_ID)
)
create table RULE (
   RULE_ID bigint not null,
   primary key (RULE_ID)
)
create table COMPARISON_OP (
   COMPARISON_OP_ID bigint not null,
   primary key (COMPARISON_OP_ID)
)
create table OPERATION (
   OPERATION_ID bigint not null,
   primary key (OPERATION_ID)
)
create table FIELD (
   FIELD_ID bigint not null,
   primary key (FIELD_ID)
)


Is it possible that there is a problem with primary/foreign keys?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 09, 2005 9:33 pm 
Newbie

Joined: Sat Jan 08, 2005 2:23 pm
Posts: 3
Problem solved...

By accident declared my id as long in place of Long.


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