-->
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: [SOLVED] Parent Child cascade
PostPosted: Tue Apr 06, 2010 10:48 am 
Regular
Regular

Joined: Wed Mar 10, 2010 4:48 am
Posts: 106
I've solved this problem myself. In case anyone else comes across this, try adding inverse="true" to the set.

I have class Parent and Child.
If Parent is deleted I want Child to be deleted as well.
With these mapping it works, but I do get a very long error.
Can someone help me?

Mappings:
Code:
   <class name="Parent" table="parents">
      <id name="id" column="id">
         <generator class="assigned" />
      </id>

      <set name="children" table="children" cascade="delete">
         <key column="parent" />
         <one-to-many class="Child" />
      </set>
   </class>
Code:
   <class name="Child" table="children">
      <id name="id" column="id">
         <generator class="assigned" />
      </id>

      <properties name="unique" unique="true">
         <many-to-one name="parent" class="Parent" column="parent" not-null="true" />
         <many-to-one name="otherParent" class="OtherParent" column="otherParent" not-null="true" />
      </properties>
   </class>

Error:
Code:
WARN - (JDBCExceptionReporter.java:100) - SQL Error: 1048, SQLState: 23000
ERROR - (JDBCExceptionReporter.java:101) - Column 'parent' cannot be null
ERROR - (AbstractFlushingEventListener.java:324) - 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:169)
   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 panels.SystemStringPanel.askDelete(SystemStringPanel.java:270)
   at panels.SystemStringPanel.actionPerformed(SystemStringPanel.java:294)
   at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2028)
   at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2351)
   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:6348)
   at javax.swing.JComponent.processMouseEvent(JComponent.java:3255)
   at java.awt.Component.processEvent(Component.java:6113)
   at java.awt.Container.processEvent(Container.java:2085)
   at java.awt.Component.dispatchEventImpl(Component.java:4714)
   at java.awt.Container.dispatchEventImpl(Container.java:2143)
   at java.awt.Component.dispatchEvent(Component.java:4544)
   at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4618)
   at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4282)
   at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4212)
   at java.awt.Container.dispatchEventImpl(Container.java:2129)
   at java.awt.Window.dispatchEventImpl(Window.java:2475)
   at java.awt.Component.dispatchEvent(Component.java:4544)
   at java.awt.EventQueue.dispatchEvent(EventQueue.java:635)
   at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:296)
   at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:211)
   at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:201)
   at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:196)
   at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:188)
   at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
Caused by: java.sql.BatchUpdateException: Column 'parent' cannot be null
   at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:2015)
   at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1451)
   at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:70)
   at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:268)
   ... 34 more


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.