-->
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.  [ 2 posts ] 
Author Message
 Post subject: Problem deleting in cascade
PostPosted: Fri Sep 03, 2010 4:22 pm 
Newbie

Joined: Tue Aug 17, 2010 3:16 pm
Posts: 8
I want to know how can I delete an object that is related one to many to other table, 'cuz I'm having the following error:


org.hibernate.ObjectDeletedException: deleted object would be re-saved by cascade (remove deleted object from associations): [modelos.MtecForm#3]

and here is my code:

Configuration configuration = new AnnotationConfiguration();
configuration.configure("/modelos/hibernate.cfg.xml");
SessionFactory sessionFactory = configuration.buildSessionFactory();

Session session = sessionFactory.openSession();
session.beginTransaction();

Mformulario sObjTec = new Mformulario();


sObjTec = (Mformulario) session.load(Mformulario.class,
Integer.parseInt(textField.getText()));

List<MtecForm> tecnicoFormularioList = new ArrayList<MtecForm>();
tecnicoFormularioList = sObjTec.getTecnicoFormularioList();

for(MtecForm mTecForm : tecnicoFormularioList) {
session.delete(mTecForm);

}


session.delete(sObjTec);

session.getTransaction().commit();
session.close();




thanks for your help!!!


Top
 Profile  
 
 Post subject: Re: Problem deleting in cascade
PostPosted: Mon Sep 06, 2010 10:30 am 
Newbie

Joined: Tue Aug 17, 2010 3:16 pm
Posts: 8
I fix it by delete at first the list that is associate to the object that I'm going to delete. The problem was that I need to create another session to delete the list and comit first than the comit that delete the object. XD


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