-->
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: Flush during cascade is dangerous - this might occur if an o
PostPosted: Wed Jan 21, 2004 2:34 am 
Regular
Regular

Joined: Thu Dec 25, 2003 12:33 am
Posts: 58
Location: Campina Grande, Brasil
That is what i get when trying to delete an object with children. Those children are not associated with other objects. Really don't know what to do anymore.

Thanks anyway.

_________________
Ot


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 21, 2004 2:42 am 
Regular
Regular

Joined: Thu Dec 25, 2003 12:33 am
Posts: 58
Location: Campina Grande, Brasil
This is the code I'm using:

Code:
      SessionFactory sessionFactory =
         new Configuration().configure().buildSessionFactory();
      Session session;
      session = sessionFactory.openSession();
      Transaction trans = session.beginTransaction();

      Lote lote = (Lote) session.load(Lote.class, id);

      if (!(lote.isLivre())) {
         request.getSession().setAttribute("apagaLote", lote);
         session.flush();
         session.close();
         return (mapping.findForward("confirma_apaga_lote"));
      }


      ActionMessages messages = new ActionMessages();
      ActionMessage msg = new ActionMessage("msg.lote.deletado");
      messages.add(ActionMessages.GLOBAL_MESSAGE, msg);
      this.saveMessages(request, messages);

      TransDetalhaQuadra td = new TransDetalhaQuadra();
      Quadra quadra = lote.getQuadra();

      Iterator lotes = quadra.getLotes().iterator();
      Set novosLotes = new HashSet();
      while (lotes.hasNext()) {
         Lote l = (Lote) lotes.next();
         log.infoCemiterioLog("iter");
         if (l.getId() != id.longValue()) {
            novosLotes.add(l);
         }
      }
         td.setLotes(novosLotes);
         td.setQuadra(quadra);

         session.delete(lote);         
         trans.commit();
         session.close();      

         request.getSession().setAttribute("quadraAdmin",td);
         return (mapping.findForward("quadraadmin"));


Please, specialists, what is wrong ?? Still getting the message

Flush during cascade is dangerous - this might occur if an object was deleted and then re-saved by cascade

Thanks

_________________
Ot


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 21, 2004 7:21 am 
Senior
Senior

Joined: Tue Nov 25, 2003 9:35 am
Posts: 194
Location: San Francisco
You are not showing us what message you are getting.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 21, 2004 9:49 am 
Newbie

Joined: Mon Jan 12, 2004 3:25 pm
Posts: 9
Code:
      TransDetalhaQuadra td = new TransDetalhaQuadra();
      Quadra quadra = lote.getQuadra();

      Iterator lotes = quadra.getLotes().iterator();
      Set novosLotes = new HashSet();
      while (lotes.hasNext()) {
         Lote l = (Lote) lotes.next();
         log.infoCemiterioLog("iter");
         if (l.getId() != id.longValue()) {
            novosLotes.add(l);
         }
      }
         td.setLotes(novosLotes);
         td.setQuadra(quadra);

         session.delete(lote);         
         trans.commit();
         session.close();       


Look at this fragment carefully, first of all I assume that your quadra and lote is one-to-many bidirectinal relation (since lote.getQuadra(); and quadra.getLotes().iterator())

at some point you can be deleting the lote object

Code:
session.delete(lote);


at the same time you might be adding the same object (as indirectly as it is) to a collection thru the statement
Code:
if (l.getId() != id.longValue()) {
     novosLotes.add(l);
}


Hence is the message on one hand you are adding lote to a collection that is probably saved thru a cascade. On the other hand you are deleting the same object that you are trying to save.

Look at your logic carefully. I am sure you will find that the message thrown is thrown so correctly :-)

HTH,
Alex.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 23, 2004 4:05 am 
Regular
Regular

Joined: Thu Dec 25, 2003 12:33 am
Posts: 58
Location: Campina Grande, Brasil
Well, the message makes sense at all. I could solve this problem, and you got the relationship between lotes and quadras right. Now I can correctly delete lotes objects.
But check this: lotes objects are objects which have no children and two parents. The thing goes this way:

Setor have Quadras, Quadras have Lotes, Setor have Lotes. got it ?

I can delete Lotes objects. I remove it from its parent's collections and them delete it.
but I can't delete even Setor, which is the parent of everyone. I get the same message. And I get the same message when trying to delete Quadras objets as well, even if I use the sme method I used to delete Lotes: remove all Quadras from Setor collection, and them delete Quadra itself.

So, what am I missing?

Thanks a lot for your last message

_________________
Ot


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.