-->
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.  [ 9 posts ] 
Author Message
 Post subject: You may not dereference a collection...exception. Why?
PostPosted: Thu Apr 01, 2004 6:06 pm 
Pro
Pro

Joined: Mon Sep 08, 2003 4:30 pm
Posts: 203
Hi All,

Maps:

Code:
    <class name="com.db.device.NEMgmtInfo" table="nemgmtinfo" mutable="true" polymorphism="implicit" dynamic-update="false" dynamic-insert="false">
      <!--cache usage="read-write" /-->
      <id name="id" type="long" unsaved-value="0">
         <generator class="native">
         </generator>
      </id>
      <bag name="cards" lazy="true" inverse="true" cascade="all-delete-orphan">
         <key column="ne_card"/>
         <one-to-many class="com.db.device.NECard"/>
      </bag>
    </class>

    <class name="com.db.device.NECard" table="ne_card" mutable="true" polymorphism="implicit" dynamic-update="false" dynamic-insert="false">
      <id name="id" type="long" unsaved-value="0">
         <generator class="native">
         </generator>
      </id>
      <many-to-one name="ne_card" column="ne_card" class="com.db.device.NEMgmtInfo"/>

</class>


Code:

Code:
         NEMgmtInfo host1 = null;
         host1 = (NEMgmtInfo) session.load(NEMgmtInfo.class, new Long(10));

         List newList =
            session.find(
               "from com.diatem.db.device.NECard as card where card.ne_card.id = ?",
               new Long(host1.getId()),
               Hibernate.LONG);

         host1.setCards(newList);

         NEMgmtInfo host2 = null;
         host2 = (NEMgmtInfo) session.load(NEMgmtInfo.class, new Long(12));

         List newList1 =
line 114:            session.find(
               "from com.diatem.db.device.NECard as card where card.ne_card.id = ?",
               new Long(host2.getId()),
               Hibernate.LONG);



An exception is raised at the 2ns session.find()

Code:
net.sf.hibernate.HibernateException: You may not dereference a collection with cascade="all-delete-orphan"
   at net.sf.hibernate.impl.SessionImpl.updateUnreachableCollection(SessionImpl.java:2887)
   at net.sf.hibernate.impl.SessionImpl.flushCollections(SessionImpl.java:2756)
   at net.sf.hibernate.impl.SessionImpl.flushEverything(SessionImpl.java:2227)
   at net.sf.hibernate.impl.SessionImpl.autoFlushIfRequired(SessionImpl.java:1771)
   at net.sf.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:1536)
   at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1501)
   at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1491)
   at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1487)
   at com.diatem.db.device.api.MainDevice.go(MainDevice.java:114)
   at com.diatem.db.device.api.MainDevice.main(MainDevice.java:74)


Why???

TIA,
--steve p.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 01, 2004 6:20 pm 
Pro
Pro

Joined: Mon Sep 08, 2003 4:30 pm
Posts: 203
I am not getting the error if don't do:

host1.setCards(newList);


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 02, 2004 8:29 am 
Pro
Pro

Joined: Mon Sep 08, 2003 4:30 pm
Posts: 203
Can anybody help me with this?
Someone from Hibernate team, maybe.

Please. Thank you.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 02, 2004 1:47 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
all-delete-orphan requires to keep the same collection instance (the one Hibernate give) to work (it keeps the collection state).

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 02, 2004 1:50 pm 
Pro
Pro

Joined: Mon Sep 08, 2003 4:30 pm
Posts: 203
emmanuel wrote:
all-delete-orphan requires to keep the same collection instance (the one Hibernate give) to work (it keeps the collection state).


So what was I doing wrong?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 02, 2004 1:57 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Code:
host1.setCards(newList);

You're setting an new instance

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 02, 2004 2:00 pm 
Pro
Pro

Joined: Mon Sep 08, 2003 4:30 pm
Posts: 203
emmanuel wrote:
Code:
host1.setCards(newList);

You're setting an new instance


Thx, Emmanuel.

Still, how am I suppoesed to replace the old collection with a new one if I cannot do

host1.setCards()

thx.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 02, 2004 3:01 pm 
Newbie

Joined: Tue Oct 21, 2003 1:09 pm
Posts: 4
one way you can do is
Collection col = host1.getCards();
col.clear();
col.addAll(newList);


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 02, 2004 3:41 pm 
Pro
Pro

Joined: Mon Sep 08, 2003 4:30 pm
Posts: 203
hans wrote:
one way you can do is
Collection col = host1.getCards();
col.clear();
col.addAll(newList);


thx. it did the trick.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 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.