-->
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: howto one-to-one and cascade delete orphans?
PostPosted: Tue Aug 23, 2005 6:20 am 
Beginner
Beginner

Joined: Wed May 04, 2005 5:17 am
Posts: 40
Using hibernate 3.0.5.

I have setup Page (master) with a one-to-one with Lock (slave). Page.getLock() is cascade "all-delete-orphan", and Lock.getPage() is constrained:

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping default-access="field">
  <class name="uk.ac.warwick.sbr.AbstractPageImpl"
         proxy="uk.ac.warwick.sbr.Page"
         table="PAGE"
         dynamic-insert="true"
         dynamic-update="true">
    <id name="id"
        column="id"
        type="java.lang.String"
        unsaved-value="null">
        <generator class="org.hibernate.id.UUIDHexGenerator"/>
    </id>
    <one-to-one name="lock"
                cascade="all-delete-orphan"
                class="uk.ac.warwick.sbr.LockImpl"/>
  </class>

  <!-- Lock is only used as part of Page. -->
  <class name="uk.ac.warwick.sbr.LockImpl"
         proxy="uk.ac.warwick.sbr.Lock"
         lazy="true"
         table="PAGE_LOCK">
    <id name="id"
        column="id"
        type="java.lang.String">
        <generator class="foreign">
          <param name="property">page</param>
        </generator>
    </id>
    <one-to-one name="page" class="uk.ac.warwick.sbr.AbstractPageImpl" constrained="true"/>
    <property name="lockedBy" column="LOCKED_BY"/>
    <property name="lockedSince" column="LOCKED_TIME"/>
  </class>
</hibernate-mapping>



I can successfully save a lock by saving the page, and if I call page.setLock(null), then the association is indeed broken. The problem is that the row in the database still exists:

Code:
        page.setLock(null);
        ((LockImpl)lock).setPage(null);
        anotherSession.flush();

        page = (HtmlPage) anotherSession.load(HtmlPageImpl.class, page.getId());
        lock = page.getLock();
        assertNull("lock still attached to page", lock);

        List allLocks = anotherSession.createSQLQuery(
                "select {lock.*} from page_lock lock"
                )
                .addEntity("lock", LockImpl.class)
                .list();
        assertTrue("orphan row exists", allLocks.isEmpty());
    }


Ta.

Col


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 24, 2005 4:12 am 
Beginner
Beginner

Joined: Wed May 04, 2005 5:17 am
Posts: 40
anyone else have this problem?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 11, 2005 4:19 am 
Beginner
Beginner

Joined: Thu Jun 02, 2005 5:09 am
Posts: 22
yes, check out http://forum.hibernate.org/viewtopic.php?t=947880&highlight=onetoone+cascade

Can't help you out though, as I am just as confused as you are that this doesn't work like we all expect it to.

Joris


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.