-->
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: Flush during cascade is dangerous
PostPosted: Sat Sep 13, 2003 3:24 pm 
Regular
Regular

Joined: Wed Sep 03, 2003 9:56 pm
Posts: 58
I think I have a problem with my cascade logic, but I can't put my finger on it. My model is as follows,
Code:
User(1)-----(*)Entitlement(*)-----(1)Group
                   (*)
                    |
                   Role

I am using a Component relationship between User and Entitlement, and many-to-one between Entitlement and User/Group/Role (See hbm.xml files below).

I get the "Flush during cascade is dangerous" exception whenever I try to delete a User, as follows,
Code:
User user = (User)session.load(User.class, userId) ;
session.delete(user) ;

I've tried iterating and removing each Entitlement, and this works as long as I don't delete the User. If I delete all Entitlements, and then try to delete the User, I get the same "Flush..." exception.

Any Suggestions?

Code:
<hibernate-mapping>
    <class name="he2.User" table="SEC2_USER">
        <id column="ID" name="id">...</id>
        <property column="name" name="name"/>
        <set cascade="all" name="entitlements" table="ENTITLEMENT">
            <key column="ID"/>
            <composite-element class="Entitlement">
                <many-to-one cascade="save-update" name="user" column="USER_ID" class="User"/>
                <many-to-one cascade="save-update" name="group" column="GROUP_ID" class="Group"/>
                <many-to-one cascade="save-update" name="role" column="ROLE_ID" class="Role"/>
            </composite-element>
        </set>
    </class>

    <class name="Entitlement" table="ENTITLEMENT">
        <id column="ID" name="id">...</id>
        <many-to-one cascade="all" class="User" column="USER_ID" name="user"/>
        <many-to-one cascade="save-update" class="Group" column="GROUP_ID" name="group"/>
        <many-to-one cascade="save-update" class="Role" column="ROLE_ID" name="role"/>
    </class>

</hibernate-mapping>

    <class name="Group" table="GROUP">
        <id column="ID" name="id">...</id>
        <property column="name" name="name"/>
        <set cascade="all" name="entitlements">
            <key column="GROUP_ID"/>
            <one-to-many class="Entitlement"/>
        </set>
    </class>

    <class name="he2.Role" table="ROLE">
        <id column="ID" name="id">...</id>
        <property column="name" name="name"/>
        <set cascade="all" name="entitlements">
            <key column="ROLE_ID"/>
            <one-to-many class="Entitlement"/>
        </set>
    </class>



Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 13, 2003 4:30 pm 
Regular
Regular

Joined: Wed Sep 03, 2003 9:56 pm
Posts: 58
Ok. I may have solved my own problem

Removing all cascades from the Entitlement seemed to have done the trick.

-Mitch


Top
 Profile  
 
 Post subject:
PostPosted: Sun Sep 14, 2003 1:00 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
If you delete an object, you have to remove it from ANY association that is marked cascade="save-update".


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.