-->
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.  [ 1 post ] 
Author Message
 Post subject: DELETE one-to-many, many-to-one objects
PostPosted: Mon Mar 16, 2009 11:34 am 
Newbie

Joined: Mon Mar 16, 2009 11:24 am
Posts: 1
Hello, I've got aproblem with parent-child relationship, i want to delete parent and all the childrens but i get an exception.

Thanks

Hibernate version: 3.3.1

Mapping documents:
Code:
   <class name="model.Dostawca" lazy="false" table="DOSTAWCA">
      <id name="id" column="DOSTAWCA_ID">
         <generator class="native" />
      </id>
      <property name="nazwa" />
      <property name="miasto" />
      <list name="polprodukty"  cascade="all,delete"  table="DOSTAWCA_POLPRODUKTY" lazy="false" inverse="false">
         <key column="ID" />
         <index column="idx" />
         <one-to-many class="model.Polprodukt" />
      </list>
   </class>

   <class name="model.Polprodukt" lazy="false" table="POLPRODUKT">
      <id name="id" column="POLPRODUKT_ID">
         <generator class="native" />
      </id>
      <property name="nazwa" />
      <property name="symbol" />
      <property name="stan" />
      <many-to-one name="dostawca" class="model.Dostawca" column="DOSTAWCA_ID" not-null="true"  insert="false" update="false"/>
   </class>



Code between sessionFactory.openSession() and session.close():
Code:
        Session session = sessionFactory.getCurrentSession();
        session.beginTransaction();       
        session.delete(o);
        session.getTransaction().commit(); 

Full stack trace of any exception that occurs:
Code:
Hibernate: delete from DOSTAWCA where DOSTAWCA_ID=?
2009-03-16 16:27:39 org.hibernate.util.JDBCExceptionReporter logExceptions
WARNING: SQL Error: 23003, SQLState: 23003
2009-03-16 16:27:39 org.hibernate.util.JDBCExceptionReporter logExceptions
SEVERE: Referential integrity constraint violation: FK74446FAF978C2FF: PUBLIC.POLPRODUKT FOREIGN KEY(DOSTAWCA_ID) REFERENCES PUBLIC.DOSTAWCA(DOSTAWCA_ID) [23003-79]
2009-03-16 16:27:39 org.hibernate.util.JDBCExceptionReporter logExceptions
WARNING: SQL Error: 23003, SQLState: 23003
2009-03-16 16:27:39 org.hibernate.util.JDBCExceptionReporter logExceptions
SEVERE: Referential integrity constraint violation: FK74446FAF978C2FF: PUBLIC.POLPRODUKT FOREIGN KEY(DOSTAWCA_ID) REFERENCES PUBLIC.DOSTAWCA(DOSTAWCA_ID) [23003-79]
2009-03-16 16:27:39 org.hibernate.event.def.AbstractFlushingEventListener performExecutions
SEVERE: Could not synchronize database state with session
org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
   at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:94)
   at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
   at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:275)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:266)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:172)
   at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
   at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)
   at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1027)
   at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:365)
   at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:137)
   at util.HibernateUtil.deleteObject(HibernateUtil.java:82)
   at controller.SystemMagazynowyController.usunDostawce(SystemMagazynowyController.java:128)
   at controller.SystemMagazynowyController.actionPerformed(SystemMagazynowyController.java:53)
   at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
   at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
   at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
   at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
   at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
   at java.awt.Component.processMouseEvent(Component.java:6134)
   at javax.swing.JComponent.processMouseEvent(JComponent.java:3265)
   at java.awt.Component.processEvent(Component.java:5899)
   at java.awt.Container.processEvent(Container.java:2023)
   at java.awt.Component.dispatchEventImpl(Component.java:4501)
   at java.awt.Container.dispatchEventImpl(Container.java:2081)
   at java.awt.Component.dispatchEvent(Component.java:4331)
   at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4301)
   at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3965)
   at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3895)
   at java.awt.Container.dispatchEventImpl(Container.java:2067)
   at java.awt.Window.dispatchEventImpl(Window.java:2458)
   at java.awt.Component.dispatchEvent(Component.java:4331)
   at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
   at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
   at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
   at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
   at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
   at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
   at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
Caused by: org.h2.jdbc.JdbcBatchUpdateException: Referential integrity constraint violation: FK74446FAF978C2FF: PUBLIC.POLPRODUKT FOREIGN KEY(DOSTAWCA_ID) REFERENCES PUBLIC.DOSTAWCA(DOSTAWCA_ID) [23003-79]
   at org.h2.jdbc.JdbcPreparedStatement.executeBatch(JdbcPreparedStatement.java:1066)
   at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:70)
   at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:268)
   ... 35 more
Exception in thread "AWT-EventQueue-0" org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
   at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:94)
   at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
   at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:275)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:266)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:172)
   at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
   at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)
   at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1027)
   at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:365)
   at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:137)
   at util.HibernateUtil.deleteObject(HibernateUtil.java:82)
   at controller.SystemMagazynowyController.usunDostawce(SystemMagazynowyController.java:128)
   at controller.SystemMagazynowyController.actionPerformed(SystemMagazynowyController.java:53)
   at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
   at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
   at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
   at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
   at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
   at java.awt.Component.processMouseEvent(Component.java:6134)
   at javax.swing.JComponent.processMouseEvent(JComponent.java:3265)
   at java.awt.Component.processEvent(Component.java:5899)
   at java.awt.Container.processEvent(Container.java:2023)
   at java.awt.Component.dispatchEventImpl(Component.java:4501)
   at java.awt.Container.dispatchEventImpl(Container.java:2081)
   at java.awt.Component.dispatchEvent(Component.java:4331)
   at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4301)
   at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3965)
   at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3895)
   at java.awt.Container.dispatchEventImpl(Container.java:2067)
   at java.awt.Window.dispatchEventImpl(Window.java:2458)
   at java.awt.Component.dispatchEvent(Component.java:4331)
   at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
   at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
   at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
   at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
   at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
   at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
   at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
Caused by: org.h2.jdbc.JdbcBatchUpdateException: Referential integrity constraint violation: FK74446FAF978C2FF: PUBLIC.POLPRODUKT FOREIGN KEY(DOSTAWCA_ID) REFERENCES PUBLIC.DOSTAWCA(DOSTAWCA_ID) [23003-79]
   at org.h2.jdbc.JdbcPreparedStatement.executeBatch(JdbcPreparedStatement.java:1066)
   at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:70)
   at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:268)
   ... 35 more


Name and version of the database you are using:
H2db
The generated SQL (show_sql=true):
Code:
Hibernate: delete from DOSTAWCA where DOSTAWCA_ID=?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.