-->
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: Bidirectional Many-to-Many still 'remembers' deleted object.
PostPosted: Thu Oct 02, 2008 5:58 am 
Beginner
Beginner

Joined: Wed Aug 27, 2003 3:46 am
Posts: 34
Location: Taiwan
Hibernate version: 3.2.6

I am simulating Flickr's Account , Album and Collection relationships.

Account and Album is a bi-directional one-to-many relationship with cascade="save-update , delete"

Collection and Album is a bi-directional many-to-many relationship

The .hbm is :
Code:
  <class name="Account">
    <cache usage="nonstrict-read-write"/>
    <id name="id" column="id" type="int">
      <generator class="increment"/>
    </id>
    <list name="albums" cascade="save-update , delete" inverse="false">
      <cache usage="nonstrict-read-write"/>
      <key column="accountId" not-null="true"/>
      <list-index column="position"/>
      <one-to-many class="Album"/>
    </list>
  </class>

  <class name="Album">
    <cache usage="nonstrict-read-write"/>
    <id name="id" column="id" type="int">
      <generator class="increment"/>
    </id>
    <many-to-one name="account" column="accountId" not-null="true" insert="false" update="false" lazy="false"/>
   
    <set name="collections"
         table="CollectionAlbum"
         cascade="save-update">
      <cache usage="nonstrict-read-write"/>
      <key column="albumId"/>
      <many-to-many class="Collection" column="collectionId"/>
    </set>
  </class>

  <class name="Collection">
    <cache usage="nonstrict-read-write"/>
    <id name="id" column="id" type="int">
      <generator class="increment"/>
    </id>

    <set name="albums"
         table="CollectionAlbum"
         inverse="true"
         cascade="save-update">
      <cache usage="nonstrict-read-write"/>
      <key column="collectionId"/>
      <many-to-many class="Album" column="albumId"/>
    </set>
  </class>


The Account-Album relationship works correctly.
The Collection-Album relationship also works correctly , I can successfully add/remove album to/from a Collection.

The problem occurs when deleting an account...
the albums belonging to the account are all automatically deleted by Hibernate ,
and the albumId in CollectionAlbum table also deleted by Hibernate.
BUT , When I retrieve a Collection , it reports :
ObjectNotFoundException: No row with the given identifier exists: [foo.bar.Album#346]
It seems Collection still 'remembers' it contains a deleted Album...
I know it can be solved by not-found="ignore" , but I feel it is ugly...

Is there any other way to solve this problem ?


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.