-->
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 with delete on first time called....
PostPosted: Sun Dec 04, 2005 1:28 pm 
Newbie

Joined: Sun Dec 04, 2005 12:36 pm
Posts: 1
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Basically... the problem in here is not sql related, at least not directly.
The mappings, the selects, the update, all work.
The problem is with the delete, i have an action event triggering a delete event(in a jtable in this case), when the action is triggered the first time, hibernate does the error that is below. But on the second try it goes fine, and so does the 3rd, etc.
Moreover, if i call twice the delete in the actionevent, it doesnt work.
The action event has to be called twice for it to work....
Here's what the action event looks like:
public void actionPerformed(ActionEvent e) {
if ("commit".equals(e.getActionCommand())) {
System.out.println("Committing data");
deleteLines();

}
}


and deleteLines:

private void deleteLines() {
for (int j =0; j<currentDeletedList.size();j++) {
Line toDelete = (Line) currentDeletedList.get(j);
Utils.deleteO(toDelete);
}

}

and deleteO:

public static void deleteO(Object toDelete) {
Session session = HibernateUtil.currentSession();
Transaction tx = session.beginTransaction();
session.delete(toDelete);
tx.commit();
}



Hibernate version:
3.0.5

Mapping documents:
N/A

Code between sessionFactory.openSession() and session.close():
a few sql requests(that work fine)

Full stack trace of any exception that occurs:
Exception in thread "AWT-EventQueue-0" org.hibernate.ObjectDeletedException: deleted object would be re-saved by cascade (remove deleted object from associations): [HiberFacture.Line#6]
at org.hibernate.impl.SessionImpl.forceFlush(SessionImpl.java:742)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:166)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:96)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:69)
at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:468)
at org.hibernate.engine.Cascades$5.cascade(Cascades.java:154)
at org.hibernate.engine.Cascades.cascadeAssociation(Cascades.java:771)
at org.hibernate.engine.Cascades.cascade(Cascades.java:720)
at org.hibernate.engine.Cascades.cascadeCollection(Cascades.java:895)
at org.hibernate.engine.Cascades.cascadeAssociation(Cascades.java:792)
at org.hibernate.engine.Cascades.cascade(Cascades.java:720)
at org.hibernate.engine.Cascades.cascade(Cascades.java:847)
at org.hibernate.event.def.AbstractFlushingEventListener.cascadeOnFlush(AbstractFlushingEventListener.java:121)
at org.hibernate.event.def.AbstractFlushingEventListener.prepareEntityFlushes(AbstractFlushingEventListener.java:112)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:59)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:730)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:324)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:86)
at HiberFac.Utils.deleteL(Utils.java:184)
at HiberFac.FacViewer.actionPerformed(FacViewer.java:232)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

Name and version of the database you are using:
oracle 10

The generated SQL (show_sql=true):
N/A

Debug level Hibernate log excerpt:
N/A


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 04, 2005 2:02 pm 
Expert
Expert

Joined: Mon Jul 04, 2005 5:19 pm
Posts: 720
two things. it looks like hibernate doesn't want to remove that entity from the db because there is still an *instance* of it referenced by another object that is in *persistent state*. you may want to check the documentation if you are not already familar w/ the 3 object states. find this ref and break it.

second, and don't get mad when I say this, but you simply should not be calling commit() for each object in the list. just pass each object to delete, and then call transaction.commit() once.


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.