Joined: Sun Jun 05, 2005 2:28 pm Posts: 3
|
Hi
I have some problems with cascading delete. It works fine if I have normal one-to-many relations. But I need to use a class with two subclasses. If I delete the Parent I get the error below. I think cascading doesn´t work. I tried to relate the Parent with the two subclasses, but it also haven´t worked.
Thanks for help
regards Indy
Parent
<class name="Trainingstagebuch" table="trainingstagebuch">
<id name="id" column="id" type="java.lang.Integer">
<generator class="native"/>
</id>
<set name="Tagebucheintrag" lazy ="true" inverse="true" cascade="all-delete-orphan">
<key>
<column name ="id"/>
</key>
<one-to-many class="Tagebucheintrag"/>
</set>
<many-to-one name="sportlerakte" class="Sportlerakte">
<column name="SportlerakteID" unique="true"/>
</many-to-one>
</class>
Child
<class name="Tagebucheintrag" table="Tagebucheintrag">
<id name="id" column="id" type="java.lang.Integer">
<generator class="native"/>
</id>
<property name="datum" column="datum" type="java.util.Date"/>
<many-to-one name="Trainingstagebuch" class="Trainingstagebuch" >
<column name="TrainingstagebuchID"/>
</many-to-one>
<joined-subclass name="Tagesdaten" table="tagesdaten">
<key column="id"/>
<property name="befinden" column="befinden" type="java.lang.String" />
<property name="ruhepuls" column="ruhepuls" type="int" />
</joined-subclass>
<joined-subclass name="Trainingseinheit" table="trainingseinheit">
<key column="id"/>
<property name="zielvorgabe" column="zielvorgabe" type="java.lang.String" />
</joined-subclass>
</class>
Hibernate version: 2.1
Full stack trace of any exception that occurs:
net.sf.hibernate.exception.ConstraintViolationException: could not insert: [de.tum.in.msa.model.Hbm.Tagesdaten]
at net.sf.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:73)
at net.sf.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:30)
at net.sf.hibernate.persister.AbstractEntityPersister.convert(AbstractEntityPersister.java:1332)
at net.sf.hibernate.persister.NormalizedEntityPersister.insert(NormalizedEntityPersister.java:554)
at net.sf.hibernate.persister.NormalizedEntityPersister.insert(NormalizedEntityPersister.java:419)
at net.sf.hibernate.impl.ScheduledIdentityInsertion.execute(ScheduledIdentityInsertion.java:29)
at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:941)
at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:866)
at net.sf.hibernate.impl.SessionImpl.saveWithGeneratedIdentifier(SessionImpl.java:784)
at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:747)
at de.tum.in.msa.model.Hbm.base._BaseRootDAO.save(_BaseRootDAO.java:624)
at de.tum.in.msa.model.Hbm.base._BaseRootDAO.save(_BaseRootDAO.java:605)
at de.tum.in.msa.model.Hbm.base.BaseTagesdatenDAO.save(BaseTagesdatenDAO.java:60)
at de.tum.in.msa.tests.model.UserTest.testAddTagesdaten(UserTest.java:130)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:421)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:305)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:186)
Caused by: java.sql.SQLException: Cannot add or update a child row: a foreign key constraint fails
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2851)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1531)
at com.mysql.jdbc.ServerPreparedStatement.serverExecute(ServerPreparedStatement.java:1366)
at com.mysql.jdbc.ServerPreparedStatement.executeInternal(ServerPreparedStatement.java:952)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1974)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1897)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1758)
at net.sf.hibernate.persister.NormalizedEntityPersister.insert(NormalizedEntityPersister.java:513)
... 25 more
Name and version of the database you are using:MySQL 4.1
|
|