-->
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.  [ 6 posts ] 
Author Message
 Post subject: Flush during cascade is dangerous
PostPosted: Wed Feb 18, 2004 2:42 pm 
Newbie

Joined: Thu Feb 12, 2004 2:58 am
Posts: 6
I'm getting "Flush during cascade is dangerous" exception when I try to delete a record. Would anybody happened to know what might caused it? Here is the detail specs:


1. Hibernate version 2.0

2. Mapping Documents

<hibernate-mapping>
<class
name="karta.planet.Event"
table="Event"
dynamic-update="false"
dynamic-insert="false"
>

<id
name="id"
column="event_id"
type="java.lang.String"
>
<generator class="uuid.hex">
</generator>
</id>

<many-to-one
name="account"
class="karta.planet.Account"
cascade="none"
outer-join="auto"
update="true"
insert="true"
column="account_id"
/>

<many-to-one
name="item"
class="karta.planet.Item"
cascade="none"
outer-join="auto"
update="true"
insert="true"
column="item_id"
/>

<property
name="name"
type="java.lang.String"
update="true"
insert="true"
column="name"
/>

<property
name="type"
type="java.lang.String"
update="true"
insert="true"
column="type"
/>

<many-to-one
name="boundary"
class="karta.planet.Boundary"
cascade="none"
outer-join="auto"
update="true"
insert="true"
column="boundary_id"
/>

<property
name="boundaryParam"
type="java.lang.String"
update="true"
insert="true"
column="boundary_param"
/>

<property
name="startDate"
type="java.util.Date"
update="true"
insert="true"
column="start_date"
/>

<property
name="endDate"
type="java.util.Date"
update="true"
insert="true"
column="end_date"
/>

<property
name="startTime"
type="java.sql.Time"
update="true"
insert="true"
column="start_time"
/>

<property
name="endTime"
type="java.sql.Time"
update="true"
insert="true"
column="end_time"
/>

<property
name="sunday"
type="boolean"
update="true"
insert="true"
column="sunday"
/>

<property
name="monday"
type="boolean"
update="true"
insert="true"
column="monday"
/>

<property
name="tuesday"
type="boolean"
update="true"
insert="true"
column="tuesday"
/>

<property
name="wednesday"
type="boolean"
update="true"
insert="true"
column="wednesday"
/>

<property
name="thursday"
type="boolean"
update="true"
insert="true"
column="thursday"
/>

<property
name="friday"
type="boolean"
update="true"
insert="true"
column="friday"
/>

<property
name="saturday"
type="boolean"
update="true"
insert="true"
column="saturday"
/>

<property
name="week1"
type="boolean"
update="true"
insert="true"
column="week1"
/>

<property
name="week2"
type="boolean"
update="true"
insert="true"
column="week2"
/>

<property
name="week3"
type="boolean"
update="true"
insert="true"
column="week3"
/>

<property
name="week4"
type="boolean"
update="true"
insert="true"
column="week4"
/>

<property
name="week5"
type="boolean"
update="true"
insert="true"
column="week5"
/>

<property
name="speedKH"
type="java.lang.Integer"
update="true"
insert="true"
column="speed_k_h"
/>

<property
name="delay"
type="int"
update="true"
insert="true"
column="delay"
/>

<property
name="message"
type="java.lang.String"
update="true"
insert="true"
column="message"
/>

<set
name="recipients"
table="Event_Recipient"
lazy="false"
inverse="false"
cascade="all"
sort="unsorted"
>

<key
column="event_id"
/>

<many-to-many
class="karta.planet.Recipient"
column="recipient_id"
outer-join="auto"
/>

</set>

<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-Event.xml
containing the additional properties and place it in your merge dir.
-->

</class>

</hibernate-mapping>


3. Java Code between sessionFactory.openSession() and session.close()
SessionFactory sessionFactory = (SessionFactory) ctx.lookup("java:comp/env/hibernate/SessionFactory");
Session dbSession = sessionFactory.openSession();

try {
Transaction tx = dbSession.beginTransaction();
try {
Event event = (Event) dbSession.load(Event.class, request.getParameter("event_id"));
dbSession.delete(event);
tx.commit();
response.sendRedirect("index.jsp");
}
finally {
tx.rollback();
}
}
finally {
dbSession.close();
}



4. Full Stack Trace of exception
net.sf.hibernate.HibernateException: Flush during cascade is dangerous
- this might occur if an object was deleted and then re-saved by cascade
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2001)
at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:589)
at net.sf.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:1187)
at net.sf.hibernate.engine.Cascades$3.cascade(Cascades.java:88)
at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:258)
at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:298)
at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:341)
at net.sf.hibernate.impl.SessionImpl.preFlushEntities(SessionImpl.java:2285)
at net.sf.hibernate.impl.SessionImpl.flushEverything(SessionImpl.java:2015)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2004)
at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:57)
at _notifications._eventdelete__jsp._jspService(/notifications/eventDelete.jsp:20)
at com.caucho.jsp.JavaPage.service(JavaPage.java:75)
at com.caucho.jsp.Page.subservice(Page.java:506)
at com.caucho.server.http.FilterChainPage.doFilter(FilterChainPage.java:182)
at karta.hibernate.HibernateFilter.doFilter(HibernateFilter.java:38)
at com.caucho.server.http.FilterChainFilter.doFilter(FilterChainFilter.java:88)
at com.caucho.server.http.Invocation.service(Invocation.java:315)
at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:246)
at com.caucho.server.http.HttpRequest.handleConnection(HttpRequest.java:163)
at com.caucho.server.TcpConnection.run(TcpConnection.java:139)
at java.lang.Thread.run(Thread.java:536)

5. PostgreSQL 7.2.1


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 18, 2004 2:45 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
http://www.hibernate.org/117.html#A22


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 18, 2004 2:59 pm 
Newbie

Joined: Thu Feb 12, 2004 2:58 am
Posts: 6
Quote:
This almost always happens because you forgot to remove a deleted instance from an association with cascading save enabled. You should remove deleted objects from associations before flushing the session.



I read this, but I'm really a beginner in Hibernate. How do you remove a deleted objects from associations? Would you be so kind to explain this to me?

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 19, 2004 3:46 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Code:
child.setPArent(null);
parent.getChildren().remove(child);
session.delete(child);

It's a plain Java relation

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 19, 2004 1:05 pm 
Newbie

Joined: Thu Feb 12, 2004 2:58 am
Posts: 6
I tried set the children to null, but still doesn't work. this is what I did,

event.setRecipients(null);
dbSession.delete(event);

Am I missing something?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 19, 2004 2:06 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
I did not ask you to set children to null. Just remove the appropriate child See my code.

But I would recommand you to download the sample app and check how it works

_________________
Emmanuel


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