-->
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: Deletes with unidirectional many-to-one mapping
PostPosted: Mon Oct 20, 2008 3:59 pm 
Newbie

Joined: Mon Oct 20, 2008 3:33 pm
Posts: 1
Hi all. I'm running into an issue migrating to hibernate that I've not been able to solve.

I'm modeling servers connected to a cluster. A server has a property that indicates what cluster the server was last connected to. The cluster does not have a reference back to what comm servers was last connected to the cluster.


I've recently migrated from JDO. In JDO I provided a hint in the mapping, and had the foreign key constraint was "on delete set null". If I do the same I get "org.hibernate.ObjectNotFoundException: No row with the given identifier exists" when I load a server object after I delete a cluster entity. I figured this is because hibernate is not aware of the field changing to null in the DB, and it's not flushing the server cache.
If I'm not using the "on delete set null" feture of the foreign key constraint, hibernate is violating the constraint.

This is a simplified version of the mapping I'm using
Code:
  <class name="Server" table="servers">
        <cache usage="read-write"/>

        <id name="key" column="commserverKey" type="long">
            <generator class="sequence">
                <param name="sequence">sq_servers</param>
            </generator>
        </id>
        <version name="objectVersion" access="field" type="long"/>
        <property name="hostId" not-null="true"/>
        <many-to-one name="cluster" column="clusterkey" class="Cluster"/>
        <many-to-one name="lastCluster" column="lastCluster" class="Cluster"/>
  </class>

    <class name="Cluster" table="clusters">
        <cache usage="read-write"/>

        <id name="key" column="clusterkey" type="long">
            <generator class="sequence">
                <param name="sequence">sq_clusters</param>
            </generator>
        </id>
        <version name="objectVersion" access="field" type="long"/>
        <property name="binaryVersion" not-null="true" length="255"/>
        <set name="servers">
            <key column="clusterkey"/>
            <one-to-many class="Server"/>
        </set>
   </class>


How can I do the mapping in a way that the lastCluster property of the servers will be set to null when a cluster is deleted?

I guess one possible solution is to set the lastCluster property to not-found="ignore", and have the DB set the column to null on delete. Is that a feasible solution?


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.