-->
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: one instance variable used by to two different properties
PostPosted: Tue Dec 09, 2003 7:17 pm 
Newbie

Joined: Tue Dec 09, 2003 2:27 am
Posts: 7
Location: Sydney -
I'm trying to setup a relationship where a composite class can have one of two parents. I have inadvertently created a situation where "one instance variable which is used by to two different properties, one on the superclass, one on the subclass" (thought I not sure which instance variable this is).

This causes the child to parent reference get set to null when an existing graph is retrieved from the DB and then saveOrUpdate is called with no changes made to the graph.

I can work around the issue if I disable the setParent method if the parent provided is null. But I'm not sure of the consequences of doing this neither in my code or in hibernate. Does work around effect performance.

Is it possible to get a bit of an explanation why this doesn't work and any suggestions on how I should refractor this would be greatly appreciated


Regards
Gary

I have the following:

Code:
Class hierarchy
==========
     Model
       |
   ---------
   |         |
  Root   NodeElem
            |
        -----------
        |            |
       Node       Leaf

Object Graph
========
  root -> nodes
  node -> nodeelems
All these relationships are bidirectional
Therefore a node's parent can either be a Root or a NodeElem.

Mapping file
========
<hibernate-mapping>
    <class name="net.sf.hibernate.examples.Root" table="eg_root" dynamic-update="false" dynamic-insert="false">
        <id name="id" column="id" type="java.lang.String" unsaved-value="null">
            <generator class="uuid.hex"/>
        </id>
        <version name="version" type="int" column="version"/>
        <bag name="nodes" lazy="false" inverse="true" cascade="save-update">
            <key column="root_id"/>
            <one-to-many class="net.sf.hibernate.examples.Node"/>
        </bag>
    </class>
         
    <class name="net.sf.hibernate.examples.NodeElem" table="eg_nodeelem" dynamic-update="false" dynamic-insert="false">
        <id name="id" column="id" type="java.lang.String" unsaved-value="null">
            <generator class="uuid.hex"/>
        </id>
        <version name="version" type="int" column="version"/>
        <many-to-one name="parentNodeElem" column="node_id" not-null="false" cascade="save-update"/>

        <joined-subclass name="net.sf.hibernate.examples.Node" table="eg_node" dynamic-update="false" dynamic-insert="false">
            <key column="id"/>
            <many-to-one name="parentRoot" column="root_id" not-null="false" cascade="save-update"/>
            <bag name="nodeElem" table="NodeElem" lazy="false" inverse="true" cascade="save-update">
                <key column="node_id"/>
                <one-to-many class="net.sf.hibernate.examples.NodeElem"/>
            </bag>
        </joined-subclass>

        <joined-subclass name="net.sf.hibernate.examples.Leaf" table="eg_leaf" dynamic-update="false" dynamic-insert="false">
            <key column="id"/>
            <property name="name" type="java.lang.String" update="true" insert="true" column="name"/>
        </joined-subclass>
    </class>
</hibernate-mapping>



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.