-->
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.  [ 5 posts ] 
Author Message
 Post subject: delete-orphan causing assertion failure
PostPosted: Tue May 31, 2005 8:51 pm 
Newbie

Joined: Tue May 03, 2005 7:24 pm
Posts: 1
I have 2 classes in a bidirectional mapping: A->B one to many, B->A many to one relationship. When I have delete-orphan enabled on the A->B association, I get "AssertionFailure: owner not associated with session" whenever I attempt to delete an object A (regardless of whether it has any B children). The delete-orphan functionality works otherwise, it just prevents successful deletion of any parent (A) objects. Any ideas where the problem is?


Hibernate version: 3.05
Name and version of the database you are using: mysql Ver 14.7 Distrib 4.1.10

Code between sessionFactory.openSession() and session.close():
Code:
Transaction tx = sess.beginTransaction();
User u = (User) sess.load(User.class, new Integer(405305));
sess.delete(u);
tx.commit();

Debug level Hibernate log excerpt:
17:43:27,539 DEBUG Loader:1368 - done entity load
17:43:27,539 DEBUG DefaultDeleteEventListener:91 - deleting a persistent instance
17:43:27,539 DEBUG DefaultDeleteEventListener:126 - deleting [edu.ucsd.netDB.User#405305]
17:43:27,549 DEBUG SessionImpl:1071 - setting cache mode to: GET
17:43:27,609 DEBUG Cascades:836 - processing cascade ACTION_DELETE for: edu.ucsd.netDB.User
17:43:27,619 DEBUG Cascades:890 - cascade ACTION_DELETE for collection: edu.ucsd.netDB.User.mail
17:43:27,619 DEBUG Cascades:67 - cascading to delete: edu.ucsd.netDB.Mail
17:43:27,619 DEBUG DefaultDeleteEventListener:91 - deleting a persistent instance
17:43:27,619 DEBUG DefaultDeleteEventListener:126 - deleting [edu.ucsd.netDB.Mail#216660]
17:43:27,619 DEBUG SessionImpl:1071 - setting cache mode to: GET
17:43:27,619 DEBUG Cascades:836 - processing cascade ACTION_DELETE for: edu.ucsd.netDB.Mail
17:43:27,709 DEBUG Cascades:861 - done processing cascade ACTION_DELETE for: edu.ucsd.netDB.Mail
17:43:27,709 DEBUG SessionImpl:1071 - setting cache mode to: GET
17:43:27,709 DEBUG SessionImpl:1071 - setting cache mode to: GET
17:43:27,709 DEBUG Cascades:836 - processing cascade ACTION_DELETE for: edu.ucsd.netDB.Mail
17:43:27,709 DEBUG Cascades:861 - done processing cascade ACTION_DELETE for: edu.ucsd.netDB.Mail
17:43:27,759 DEBUG SessionImpl:1071 - setting cache mode to: GET
17:43:27,769 DEBUG Cascades:908 - done cascade ACTION_DELETE for collection: edu.ucsd.netDB.User.mail
17:43:27,769 DEBUG Cascades:919 - deleting orphans for collection: edu.ucsd.netDB.User.mail
17:43:27,809 DEBUG Cascades:929 - done deleting orphans for collection: edu.ucsd.netDB.User.mail
17:43:27,809 DEBUG Cascades:861 - done processing cascade ACTION_DELETE for: edu.ucsd.netDB.User
17:43:27,809 DEBUG SessionImpl:1071 - setting cache mode to: NORMAL
17:43:27,809 DEBUG SessionImpl:1071 - setting cache mode to: GET
17:43:27,809 DEBUG Cascades:836 - processing cascade ACTION_DELETE for: edu.ucsd.netDB.User
17:43:27,829 DEBUG Cascades:861 - done processing cascade ACTION_DELETE for: edu.ucsd.netDB.User
17:43:27,829 DEBUG SessionImpl:1071 - setting cache mode to: NORMAL
17:43:27,829 DEBUG JDBCTransaction:83 - commit
17:43:27,859 DEBUG SessionImpl:323 - automatically flushing session
17:43:27,879 DEBUG AbstractFlushingEventListener:52 - flushing session
17:43:27,879 DEBUG AbstractFlushingEventListener:102 - processing flush-time cascades
17:43:27,899 DEBUG AbstractFlushingEventListener:150 - dirty checking collections
Exception in thread "main" org.hibernate.AssertionFailure: owner not associated with session


Full stack trace of any exception that occurs:
Code:
Exception in thread "main" org.hibernate.AssertionFailure: owner not associated with session
    at org.hibernate.engine.Collections.processDereferencedCollection(Collections.java:66)
    at org.hibernate.engine.Collections.processUnreachableCollection(Collections.java:38)
    at org.hibernate.event.def.AbstractFlushingEventListener.flushCollections(AbstractFlushingEventListener.java:211)
    at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:71)
    at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26)
    at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:730)
    at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:324)
    at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:86)
    at edu.ucsd.netDB.Main.main(Main.java:59)
17:25:34,115 DEBUG Collections:50 - Collection dereferenced: [edu.ucsd.netDB.User.mail#ktbowen2]
17:25:34,115 ERROR AssertionFailure:22 - an assertion failure occured (this may indicate a bug in Hibernate, but is more likely due to unsafe use of the session)
org.hibernate.AssertionFailure: owner not associated with session
    at org.hibernate.engine.Collections.processDereferencedCollection(Collections.java:66)
    at org.hibernate.engine.Collections.processUnreachableCollection(Collections.java:38)
    at org.hibernate.event.def.AbstractFlushingEventListener.flushCollections(AbstractFlushingEventListener.java:211)
    at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:71)
    at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26)
    at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:730)
    at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:324)
    at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:86)
    at edu.ucsd.netDB.Main.main(Main.java:59)


The generated SQL (show_sql=true):
Code:
17:43:25,816 DEBUG BasicEntityPersister:2220 - Static SQL for entity: edu.ucsd.netDB.Mail
17:43:25,816 DEBUG BasicEntityPersister:2222 -  Version select: select id from mail where id =?
17:43:25,816 DEBUG BasicEntityPersister:2223 -  Snapshot select: select mail_.id, mail_.mailbox as mailbox1_, mail_.pager as pager1_, mail_.url as url1_, mail_.apop as apop1_, mail_.cram as cram1_, mail_.expiration as expiration1_, mail_.alias as alias1_, mail_.userid as userid1_ from mail mail_ where mail_.id=?
17:43:25,886 DEBUG BasicEntityPersister:2225 -  Insert 0: insert into mail (mailbox, pager, url, apop, cram, expiration, alias, userid, id) values (?, ?, ?, ?, ?, ?, ?, ?, ?)
17:43:25,886 DEBUG BasicEntityPersister:2226 -  Update 0: update mail set mailbox=?, pager=?, url=?, apop=?, cram=?, expiration=?, alias=?, userid=? where id=?
17:43:25,886 DEBUG BasicEntityPersister:2227 -  Delete 0: delete from mail where id=?
17:43:25,886 DEBUG BasicEntityPersister:2230 -  Identity insert: insert into mail (mailbox, pager, url, apop, cram, expiration, alias, userid) values (?, ?, ?, ?, ?, ?, ?, ?)
17:43:26,096 DEBUG BasicEntityPersister:2220 - Static SQL for entity: edu.ucsd.netDB.User
17:43:26,096 DEBUG BasicEntityPersister:2222 -  Version select: select id from user where id =?
17:43:26,096 DEBUG BasicEntityPersister:2223 -  Snapshot select: select user_.id, user_.userid as userid0_, user_.mailname as mailname0_, user_.status as status0_, user_.datecreated as datecrea5_0_, user_.updatetime as updatetime0_, user_.expiration as expiration0_, user_.flags as flags0_, user_.permission as permission0_, user_.affiliation as affilia10_0_, user_.dialreg as dialreg0_, user_.studentid as studentid0_, user_.staffid as staffid0_, user_.otherid as otherid0_, user_.sponsor as sponsor0_ from user user_ where user_.id=?
17:43:26,157 DEBUG BasicEntityPersister:2225 -  Insert 0: insert into user (userid, mailname, status, datecreated, updatetime, expiration, flags, permission, affiliation, dialreg, studentid, staffid, otherid, sponsor, id) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
17:43:26,157 DEBUG BasicEntityPersister:2226 -  Update 0: update user set userid=?, mailname=?, status=?, datecreated=?, updatetime=?, expiration=?, flags=?, permission=?, affiliation=?, dialreg=?, studentid=?, staffid=?, otherid=?, sponsor=? where id=?
17:43:26,207 DEBUG BasicEntityPersister:2227 -  Delete 0: delete from user where id=?
17:43:26,207 DEBUG BasicEntityPersister:2230 -  Identity insert: insert into user (userid, mailname, status, datecreated, updatetime, expiration, flags, permission, affiliation, dialreg, studentid, staffid, otherid, sponsor) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
17:43:26,217 DEBUG AbstractCollectionPersister:479 - Static SQL for collection: edu.ucsd.netDB.User.mail
17:43:26,217 DEBUG AbstractCollectionPersister:480 -  Row insert: update mail set userid=? where id=?
17:43:26,247 DEBUG AbstractCollectionPersister:482 -  Row delete: update mail set userid=null where userid=? and id=?
17:43:26,247 DEBUG AbstractCollectionPersister:483 -  One-shot delete: update mail set userid=null where userid=?
17:43:26,277 DEBUG EntityLoader:95 - Static select for entity edu.ucsd.netDB.Mail: select mail0_.id as id0_, mail0_.mailbox as mailbox1_0_, mail0_.pager as pager1_0_, mail0_.url as url1_0_, mail0_.apop as apop1_0_, mail0_.cram as cram1_0_, mail0_.expiration as expiration1_0_, mail0_.alias as alias1_0_, mail0_.userid as userid1_0_ from mail mail0_ where mail0_.id=?
17:43:26,327 DEBUG EntityLoader:95 - Static select for entity edu.ucsd.netDB.Mail: select mail0_.id as id0_, mail0_.mailbox as mailbox1_0_, mail0_.pager as pager1_0_, mail0_.url as url1_0_, mail0_.apop as apop1_0_, mail0_.cram as cram1_0_, mail0_.expiration as expiration1_0_, mail0_.alias as alias1_0_, mail0_.userid as userid1_0_ from mail mail0_ where mail0_.id=?
17:43:26,327 DEBUG EntityLoader:95 - Static select for entity edu.ucsd.netDB.Mail: select mail0_.id as id0_, mail0_.mailbox as mailbox1_0_, mail0_.pager as pager1_0_, mail0_.url as url1_0_, mail0_.apop as apop1_0_, mail0_.cram as cram1_0_, mail0_.expiration as expiration1_0_, mail0_.alias as alias1_0_, mail0_.userid as userid1_0_ from mail mail0_ where mail0_.id=? for update
17:43:26,367 DEBUG EntityLoader:95 - Static select for entity edu.ucsd.netDB.Mail: select mail0_.id as id0_, mail0_.mailbox as mailbox1_0_, mail0_.pager as pager1_0_, mail0_.url as url1_0_, mail0_.apop as apop1_0_, mail0_.cram as cram1_0_, mail0_.expiration as expiration1_0_, mail0_.alias as alias1_0_, mail0_.userid as userid1_0_ from mail mail0_ where mail0_.id=? for update
17:43:26,367 DEBUG EntityLoader:95 - Static select for entity edu.ucsd.netDB.User: select user0_.id as id0_, user0_.userid as userid0_0_, user0_.mailname as mailname0_0_, user0_.status as status0_0_, user0_.datecreated as datecrea5_0_0_, user0_.updatetime as updatetime0_0_, user0_.expiration as expiration0_0_, user0_.flags as flags0_0_, user0_.permission as permission0_0_, user0_.affiliation as affilia10_0_0_, user0_.dialreg as dialreg0_0_, user0_.studentid as studentid0_0_, user0_.staffid as staffid0_0_, user0_.otherid as otherid0_0_, user0_.sponsor as sponsor0_0_ from user user0_ where user0_.id=?
17:43:26,387 DEBUG EntityLoader:95 - Static select for entity edu.ucsd.netDB.User: select user0_.id as id0_, user0_.userid as userid0_0_, user0_.mailname as mailname0_0_, user0_.status as status0_0_, user0_.datecreated as datecrea5_0_0_, user0_.updatetime as updatetime0_0_, user0_.expiration as expiration0_0_, user0_.flags as flags0_0_, user0_.permission as permission0_0_, user0_.affiliation as affilia10_0_0_, user0_.dialreg as dialreg0_0_, user0_.studentid as studentid0_0_, user0_.staffid as staffid0_0_, user0_.otherid as otherid0_0_, user0_.sponsor as sponsor0_0_ from user user0_ where user0_.id=?
17:43:26,417 DEBUG EntityLoader:95 - Static select for entity edu.ucsd.netDB.User: select user0_.id as id0_, user0_.userid as userid0_0_, user0_.mailname as mailname0_0_, user0_.status as status0_0_, user0_.datecreated as datecrea5_0_0_, user0_.updatetime as updatetime0_0_, user0_.expiration as expiration0_0_, user0_.flags as flags0_0_, user0_.permission as permission0_0_, user0_.affiliation as affilia10_0_0_, user0_.dialreg as dialreg0_0_, user0_.studentid as studentid0_0_, user0_.staffid as staffid0_0_, user0_.otherid as otherid0_0_, user0_.sponsor as sponsor0_0_ from user user0_ where user0_.id=? for update
17:43:26,427 DEBUG EntityLoader:95 - Static select for entity edu.ucsd.netDB.User: select user0_.id as id0_, user0_.userid as userid0_0_, user0_.mailname as mailname0_0_, user0_.status as status0_0_, user0_.datecreated as datecrea5_0_0_, user0_.updatetime as updatetime0_0_, user0_.expiration as expiration0_0_, user0_.flags as flags0_0_, user0_.permission as permission0_0_, user0_.affiliation as affilia10_0_0_, user0_.dialreg as dialreg0_0_, user0_.studentid as studentid0_0_, user0_.staffid as staffid0_0_, user0_.otherid as otherid0_0_, user0_.sponsor as sponsor0_0_ from user user0_ where user0_.id=? for update
17:43:26,447 DEBUG EntityLoader:95 - Static select for entity edu.ucsd.netDB.User: select user0_.id as id0_, user0_.userid as userid0_0_, user0_.mailname as mailname0_0_, user0_.status as status0_0_, user0_.datecreated as datecrea5_0_0_, user0_.updatetime as updatetime0_0_, user0_.expiration as expiration0_0_, user0_.flags as flags0_0_, user0_.permission as permission0_0_, user0_.affiliation as affilia10_0_0_, user0_.dialreg as dialreg0_0_, user0_.studentid as studentid0_0_, user0_.staffid as staffid0_0_, user0_.otherid as otherid0_0_, user0_.sponsor as sponsor0_0_ from user user0_ where user0_.userid=?
17:43:26,467 DEBUG OneToManyLoader:106 - Static select for one-to-many edu.ucsd.netDB.User.mail: select mail0_.userid as userid1_, mail0_.id as id1_


Mapping documents:
Code:
<hibernate-mapping>
    <class name="edu.ucsd.netDB.User" table="user">
        <id name="id" type="integer" column="id">
            <generator class="identity" />     
        </id>
        <property name="userid">
            <column name="userid" sql-type="varchar(32)" not-null="true"/>
        </property>
        <property name="mailname">
            <column name="mailname" sql-type="varchar(32)" not-null="true"/>
        </property>       
        <property name="status">
            <column name="status" sql-type="enum('A','E','I')" not-null="true"/>
        </property>       
        <property name="datecreated">
            <column name="datecreated" sql-type="int(14)" not-null="true"/>
        </property>       
        <property name="updatetime">
            <column name="updatetime" sql-type="int(14)" not-null="true"/>
        </property>       
        <property name="expiration">
            <column name="expiration" sql-type="int(14)" not-null="true"/>
        </property>       
        <property name="flags">
            <column name="flags" sql-type="varchar(4)" not-null="true"/>
        </property>       
        <property name="permission">
            <column name="permission" sql-type="varchar(8)" not-null="true"/>
        </property>       
        <property name="affiliation">
            <column name="affiliation" sql-type="varchar(4)" not-null="true"/>
        </property>       
        <property name="dialreg">
            <column name="dialreg" sql-type="char(2)"/>
        </property>       
        <property name="studentid">
            <column name="studentid" sql-type="varchar(10)"/>
        </property>       
        <property name="staffid">
            <column name="staffid" sql-type="varchar(10)"/>
        </property>       
        <property name="otherid">
            <column name="otherid" sql-type="varchar(10)"/>
        </property>       
        <property name="sponsor">
            <column name="sponsor" sql-type="varchar(32)"/>
        </property>
        <set name="mail" table="mail" cascade="all, delete-orphan" inverse="true" lazy="false">
            <key column="userid" property-ref="userid" not-null="false"/>
            <one-to-many class="edu.ucsd.netDB.Mail"/>
        </set>

    </class>
</hibernate-mapping>
<hibernate-mapping>
    <class name="edu.ucsd.netDB.Mail" table="mail">
        <id name="id" type="integer" column="id">
            <generator class="native" />     
        </id>
        <property name="mailbox">
            <column name="mailbox" sql-type="varchar(40)"/>
        </property>       
        <property name="pager">
            <column name="pager" sql-type="varchar(40)"/>
        </property>       
        <property name="url">
            <column name="url" sql-type="varchar(40)"/>
        </property>       
        <property name="apop">
            <column name="apop" sql-type="varchar(10)"/>
        </property>       
        <property name="cram">
            <column name="cram" sql-type="varchar(10)"/>
        </property>       
        <property name="expiration">
            <column name="expiration" sql-type="int(14)" not-null="false"/>
        </property>     
        <property name="alias">
            <column name="alias" sql-type="varchar(20)"/>
        </property>
        <many-to-one name="user"
                 class="edu.ucsd.netDB.User"
                 cascade="save-update"
                 column="userid"
                 not-null="true"
                 property-ref="userid"/>       
    </class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 22, 2005 8:28 am 
Newbie

Joined: Tue May 17, 2005 4:54 am
Posts: 15
Location: Germany, Karlsruhe
Hi,

late answer but I hope it'll help you though:
try to insert a session.flush() after your delete-operation.

Georg


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 09, 2006 6:23 am 
Regular
Regular

Joined: Tue Nov 29, 2005 12:31 pm
Posts: 75
Hi,

Anybody any ideea on this one ? I have a similar problem.

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 18, 2007 2:32 pm 
Beginner
Beginner

Joined: Wed Jul 11, 2007 7:21 pm
Posts: 21
Location: San Diego, CA
I'm working through a similar problem, and here's what I know so far:

It's the session.flush that's doing me in

Client c = new Client();

ISession s;
ITransaction tr;

s = this.m_isf.OpenSession();
tr = s.BeginTransaction();

c = (Client)s.Get(typeof(Client), g);

s.Evict(c);
NHibernateUtil.Initialize(c);

s.Flush();
tr.Commit();
s.Close();
s.Dispose();

return c;

That the line that causes all hell to break loose on me. If I comment out the initialize / evict stuff, it changes from "owner not associated with session" to "You may not dereference an collection with cascade="all-delete-orphan". It seems like it's something related to my collections, in some way, that I'm not sure.

_________________
http://rebelheart.squarespace.com


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 18, 2007 2:34 pm 
Beginner
Beginner

Joined: Wed Jul 11, 2007 7:21 pm
Posts: 21
Location: San Diego, CA
I should add that the reason I changed it to "add-delete-orphan" was because with cascade=all, I wasn't persisting child deletions. Updates were happening okay, but no dice on deletions.

I found the description of the problem here (http://www.hibernate.org/116.html#A17), and when I changed the cascade to add-delete-orphan, the session.flush started throwing errors around. Investigating.

_________________
http://rebelheart.squarespace.com


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