Hi,
I have problems with deleting objects.
First my mappings (my questions are below..):
<hibernate-mapping>
<class name="de.avs.vt.backend.hibernate.Question"
table="Question">
<id name="questionId" column="questionId" type="integer">
<generator class="increment"/>
</id>
<property name="questionText" column="questionText" type="string" not-null="true"/>
<set name="options" cascade="all">
<key column = "questionId"/>
<one-to-many class="de.avs.vt.backend.hibernate.Option"/>
</set>
</class>
</hibernate-mapping>
<hibernate-mapping>
<class name="de.avs.vt.backend.hibernate.Option"
table="Options">
<id name="optionId" column="optionId" type="integer">
<generator class="increment"/>
</id>
<many-to-one name="questionId" class="de.avs.vt.backend.hibernate.Question" column="questionId" not-null="true"/>
<property name="optionText" column="optionText" type="string" not-null="true"/>
</class>
</hibernate-mapping>
<hibernate-mapping>
<class name="de.avs.vt.backend.hibernate.Vote"
table="Vote">
<id name="voteId" column="voteId" type="integer">
<generator class="increment"/>
</id>
<property name="ip" column="ip" type="string" not-null="false"/>
<property name="hostname" column="hostname" type="string" not-null="false"/>
<property name="datum" column="datum" type="calendar"/>
<many-to-one name="option" class="de.avs.vt.backend.hibernate.Option">
<column name="optionId"/>
</many-to-one>
<many-to-one name="sender" class="de.avs.vt.backend.hibernate.Sender">
<column name="senderId"/>
</many-to-one>
</class>
</hibernate-mapping>
<hibernate-mapping>
<class name="de.avs.vt.backend.hibernate.Sender"
table="Sender">
<id name="senderId" column="senderId" type="integer">
<generator class="increment"/>
</id>
<property name="name" column="name" type="string" not-null="true"/>
<property name="description" column="description" type="string" not-null="false"/>
</class>
</hibernate-mapping>
/*********************************************************************************/
When I try to delete a Sender, I get the following errors:
WARN JDBCExceptionReporter:38 - SQL Error: 0, SQLState: null
00:18:47,755 ERROR JDBCExceptionReporter:46 - failed batch
00:18:47,755 WARN JDBCExceptionReporter:38 - SQL Error: 0, SQLState: null
00:18:47,755 ERROR JDBCExceptionReporter:46 - failed batch
00:18:47,765 ERROR JDBCExceptionReporter:38 - Could not execute JDBC batch update
java.sql.BatchUpdateException: failed batch
I guess, this is, because there are still some votes in the database, that reference the Sender.
However, Is there a possibility to tell Hibernate to delete the votes, when I delete a Sender??
But it is important, that there should only be UNI-DIRECTIONAL Many-To-One-Association from Vote
to Sender - A Vote-object shall have an instance-Variable of the Type <Sender>, but a Senderobject
shall have no reference to the class Vote. When I say "session.delete(sender)" all related
Votes shall be deleted as well.. Is this possible?
(By the way, with this mapping, I have really difficulties with deleting objects. For instance,
I also cannot delete an <option>, Hibernates answers with these Errors:
net.sf.hibernate.ObjectDeletedException: deleted object would be re-saved by cascade (remove deleted object from associations): 1, of class: de.avs.vt.backend.hibernate.Option
at net.sf.hibernate.impl.SessionImpl.forceFlush(SessionImpl.java:752)
at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:730)
at net.sf.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:1376)
at net.sf.hibernate.engine.Cascades$4.cascade(Cascades.java:114)
at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:436)
at net.sf.hibernate.engine.Cascades.cascadeCollection(Cascades.java:526)
at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:452)
at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:503)
at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:482)
at net.sf.hibernate.impl.SessionImpl.preFlushEntities(SessionImpl.java:2673)
at net.sf.hibernate.impl.SessionImpl.flushEverything(SessionImpl.java:2250)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2239)
at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61)
at de.avs.vt.backend.hibernate.util.HibTool.exampleDelete(HibTool.java:325)
at de.avs.vt.backend.hibernate.util.ExampleSnippets.main(ExampleSnippets.java:34)
)
I would be very glad, if one of the gurus could take a look at my mapping files....THANX:
|