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: one-to-one relation with subclass.
PostPosted: Wed Jan 05, 2005 2:25 pm 
Beginner
Beginner

Joined: Tue May 11, 2004 10:40 am
Posts: 37
Location: Belgium
Let's try again...

How can I create a one-to-one relationship in a subclass with a subclass of the same root.
Example:

Class Parent;
|
|-----------------------------------------------------------------------------|
Class Subclass1 extends Parent ..............................Class Subclass2 extends Parent
private Subclass2; //==> how to map such a relation ???

Please, let me know ...
Regards, Stijn.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 06, 2005 3:42 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
you can't since a true one-to-one imply you have the said id value.

You can map it using a many-to-one however

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 07, 2005 12:08 pm 
Beginner
Beginner

Joined: Tue May 11, 2004 10:40 am
Posts: 37
Location: Belgium
Thanks for your response, but I allready tried to solve it with a many-to-one mapping, but Hibernate still gives the following error:


Code:
16:50:27,375 ERROR JDBCExceptionReporter:58 - Referential Integrity Violation. ADVENTUREBUILDER.RULE references ADVENTUREBUILDER.OPERATION
16:50:27,375 ERROR SessionImpl:2399 - Could not synchronize database state with session
net.sf.hibernate.exception.GenericJDBCException: could not insert: [syntaxtree.Rule#1]
   at net.sf.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:81)
   at net.sf.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:70)
   at net.sf.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:30)
   at net.sf.hibernate.persister.AbstractEntityPersister.convert(AbstractEntityPersister.java:1332)
   at net.sf.hibernate.persister.NormalizedEntityPersister.insert(NormalizedEntityPersister.java:467)
   at net.sf.hibernate.persister.NormalizedEntityPersister.insert(NormalizedEntityPersister.java:429)
   at net.sf.hibernate.impl.ScheduledInsertion.execute(ScheduledInsertion.java:37)
   at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2438)
   at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2391)
   at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2260)
   at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61)
   at managing.RuleManagerImpl.addRule(RuleManagerImpl.java:120)
   at managing.RuleManagerImpl.main(RuleManagerImpl.java:160)
Caused by: java.sql.SQLException: Referential Integrity Violation. ADVENTUREBUILDER.RULE references ADVENTUREBUILDER.OPERATION
   at com.pointbase.net.netJDBCPrimitives.handleResponse(Unknown Source)
   at com.pointbase.net.netJDBCPrimitives.handlePrimitiveResponse(Unknown Source)
   at com.pointbase.net.netJDBCPreparedStatement.executeUpdate(Unknown Source)
   at net.sf.hibernate.persister.NormalizedEntityPersister.insert(NormalizedEntityPersister.java:457)
   ... 8 more



I have the following sheme:

Abstract class SyntaxComponent;

2 subclasses:
Class Rule extends SyntaxComponent;
Class Operation extends SyntaxComponent;


And the subclass 'Rule' has an 'Operation' member value. And this gives the problems!


class Rule extends SyntaxComponent {
private Operation op;
...
}




I posted my mapping file below.


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.Operation"
         table="OPERATION">
         <key column="id"/> 
         <property
             name="operatorType"
             column="OPERATOR_TYPE"
             type="string"
         />
            <joined-subclass
                name="syntaxtree.ComparisonOp"
                table="COMPARISON_OP">
                <key column="id"/>
            </joined-subclass>                            
      </joined-subclass>   
           
        <joined-subclass
         name="syntaxtree.Rule"
         table="RULE">
         <key column="id"/>
         <property
             name="active"
             column="ACTIVE"
             type="boolean"
         />
            <property
             name="description"
             column="DESCRIPTION"
             type="string"
         />   
         <property
             name="scope"
             column="SCOPE"
             type="int"
         />
         <property
             name="type"
             column="TYPE"
             type="int"
            />
           
            <many-to-one name="operation" class="syntaxtree.Operation" column="OPERATION_ID" unique="true"/>
           
            <!-- <one-to-one name="operation" class="syntaxtree.Operation" constrained="true"></one-to-one>-->
                       
      </joined-subclass>   
                                                                               
    </class>
</hibernate-mapping>
[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 10, 2005 10:39 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Opration should be on the DB or somehow cascaded

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 10, 2005 10:47 am 
Beginner
Beginner

Joined: Tue May 11, 2004 10:40 am
Posts: 37
Location: Belgium
The problem was with the id. I declared it by mistake as long instead of Long.


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.