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!!!
|