Hello,
I do have a problem with deep-deleting an object and it's children. The problem seems to be, that hibernate tries to update an object i have deleted, although i did not change any properties.
The object i want to delete and it's children were created in the same session and transaction (but with a flush() and clear() inbetween the persist() and delete()).
After debugging i found, that the deleted state for the EntityEntry does not
match the entity (thus the UpdateAction is generated). The problem seems
to be a not-null many-to-one association (fremd), which is null in the deleted state (but not the 'real' entity). The property was zero'd in the deleteEntity method (with an Objektbez entity as parameter) of the DefaultDeleteEventListener class (line 171) :
new ForeignKeys.Nullifier(entity, true, false, session)
.nullifyTransientReferences( entityEntry.getDeletedState(), propTypes );
according to the hibernate log below, the update tries to set the column FREMD_ID in Objektbez to null. But the column is defined as not-null (in the mapping and the database).
Hibernate version:
3.1beta2
Mapping documents:
<class name="Objektbez" schema="SYSADM5" table="OBJEKTBEZ">
...
<many-to-one
lazy="no-proxy" name="fremd" not-null="true"
class="SuperObjekt">
<column name="FREMD_ID"/>
</many-to-one>
</class>
<class name="SuperObjekt" schema="SYSADM5" table="SUPER_OBJEKT">
<id name="id" type="java.lang.String" column="ID">
<generator class="uuid.hex"/>
</id>
...
<bag batch-size="5" cascade="none" name="objektbezFremd" inverse="true">
<key column="FREMD_ID" not-null="true"/>
<one-to-many class="de.novasib.ttsib5.hbm.SYSADM5.Objektbez"/>
</bag>
...
<joined-subclass name="Teilnetz" schema="SYSADM5" table="TEILNETZ">
<key column="ID"/>
...
</joined-subclass>
...
</class>
Code between sessionFactory.openSession() and session.close():
The complete code is a little bit too complex (too many lines of code). But here is the essence, of what i'm trying to do:
objBez = new Objectbez();
teilNetz = new Teilnetz();
persist(teilNetz);
objBez.setTeilnetz(teilNetz);
persist(objBez);
...
session.flush(); session.clear();
...
delete(objBez.getTeilnetz());
delete(objBez);
...
session.flush();
Full stack trace of any exception that occurs:
2005-08-31 08:45:19,241 DEBUG logExceptions() could not update: [de.novasib.ttsib5.hbm.SYSADM5.Objektbez#4028c0e3060b44a601060b45c09d0007] [update SYSADM5.OBJEKTBEZ set FREMD_KLASSE=?, V_GUELTIG=?, B_GUELTIG=?, STAND=?, PROJEKT_ID=?, ENR_ID=?, TTSIB_OBJ_ID=?, FREMD_ID=? where ID=?] - org.hibernate.util.JDBCExceptionReporter.logExceptions(JDBCExceptionReporter.java:63)
java.sql.BatchUpdateException: failed batch
at org.hsqldb.jdbc.jdbcStatement.executeBatch(Unknown Source)
at org.hsqldb.jdbc.jdbcPreparedStatement.executeBatch(Unknown Source)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:58)
at org.hibernate.jdbc.BatchingBatcher.addToBatch(BatchingBatcher.java:34)
at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2187)
at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:2103)
at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2357)
at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:84)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:243)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:227)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:141)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:296)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:870)
2005-08-31 08:45:19,241 WARN logExceptions() SQL Error: 0, SQLState: null - org.hibernate.util.JDBCExceptionReporter.logExceptions(JDBCExceptionReporter.java:71)
2005-08-31 08:45:19,241 ERROR logExceptions() failed batch - org.hibernate.util.JDBCExceptionReporter.logExceptions(JDBCExceptionReporter.java:72)
2005-08-31 08:45:19,241 ERROR performExecutions() Could not synchronize database state with session - org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:299)
org.hibernate.exception.GenericJDBCException: could not update: [de.novasib.ttsib5.hbm.SYSADM5.Objektbez#4028c0e3060b44a601060b45c09d0007]
Name and version of the database you are using:
HSQLDB 1.8.0.1
The generated SQL (show_sql=true):
Hibernate: update SYSADM5.OBJEKTBEZ set FREMD_KLASSE=?, V_GUELTIG=?, B_GUELTIG=?, STAND=?, PROJEKT_ID=?, ENR_ID=?, TTSIB_OBJ_ID=?, FREMD_ID=? where ID=?
Debug level Hibernate log excerpt:
2005-08-31 08:45:16,899 DEBUG flushEverythingToExecutions() flushing session - org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:58)
2005-08-31 08:45:16,899 DEBUG prepareEntityFlushes() processing flush-time cascades - org.hibernate.event.def.AbstractFlushingEventListener.prepareEntityFlushes(AbstractFlushingEventListener.java:111)
2005-08-31 08:45:16,899 DEBUG prepareCollectionFlushes() dirty checking collections - org.hibernate.event.def.AbstractFlushingEventListener.prepareCollectionFlushes(AbstractFlushingEventListener.java:153)
2005-08-31 08:45:16,914 DEBUG preFlush() Collection dirty: [de.novasib.ttsib5.hbm.SYSADM5.SuperObjekt.objektbezFremd#4028c0e3060b44a601060b45c07d0005] - org.hibernate.engine.CollectionEntry.preFlush(CollectionEntry.java:155)
2005-08-31 08:45:16,914 DEBUG preFlush() Collection dirty: [de.novasib.ttsib5.hbm.SYSADM5.TtsibObjekt.objektbez#4028c0e3060b44a601060b45bf360004] - org.hibernate.engine.CollectionEntry.preFlush(CollectionEntry.java:155)
2005-08-31 08:45:16,914 DEBUG preFlush() Collection dirty: [de.novasib.ttsib5.hbm.SYSADM5.Teilnetz.teilabschn#4028c0e3060b44a601060b45c07d0005] - org.hibernate.engine.CollectionEntry.preFlush(CollectionEntry.java:155)
2005-08-31 08:45:16,914 DEBUG flushEntities() Flushing entities and processing referenced collections - org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:170)
2005-08-31 08:45:16,914 DEBUG logDirtyProperties() de.novasib.ttsib5.hbm.SYSADM5.Objektbez.fremd is dirty - org.hibernate.persister.entity.AbstractEntityPersister.logDirtyProperties(AbstractEntityPersister.java:2838)
2005-08-31 08:45:16,914 DEBUG scheduleUpdate() Updating deleted entity: [de.novasib.ttsib5.hbm.SYSADM5.Objektbez#4028c0e3060b44a601060b45c09d0007] - org.hibernate.event.def.DefaultFlushEntityEventListener.scheduleUpdate(DefaultFlushEntityEventListener.java:206)
...
2005-08-31 08:45:20,724 DEBUG performExecutions() executing flush - org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:289)
2005-08-31 08:45:20,724 DEBUG update() Updating entity: [de.novasib.ttsib5.hbm.SYSADM5.Objektbez#4028c0e3060b44a601060b45c09d0007] - org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2134)
2005-08-31 08:45:20,724 DEBUG logOpenPreparedStatement() about to open PreparedStatement (open PreparedStatements: 0, globally: 0) - org.hibernate.jdbc.AbstractBatcher.logOpenPreparedStatement(AbstractBatcher.java:309)
2005-08-31 08:45:20,724 DEBUG log() update SYSADM5.OBJEKTBEZ set FREMD_KLASSE=?, V_GUELTIG=?, B_GUELTIG=?, STAND=?, PROJEKT_ID=?, ENR_ID=?, TTSIB_OBJ_ID=?, FREMD_ID=? where ID=? - org.hibernate.jdbc.AbstractBatcher.log(AbstractBatcher.java:344)
2005-08-31 08:45:20,724 DEBUG getPreparedStatement() preparing statement - org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:413)
2005-08-31 08:45:20,724 DEBUG dehydrate() Dehydrating entity: [de.novasib.ttsib5.hbm.SYSADM5.Objektbez#4028c0e3060b44a601060b45c09d0007] - org.hibernate.persister.entity.AbstractEntityPersister.dehydrate(AbstractEntityPersister.java:1806)
2005-08-31 08:45:20,724 DEBUG nullSafeSet() binding 'TEILNETZ' to parameter: 1 - org.hibernate.type.NullableType.nullSafeSet(NullableType.java:60)
2005-08-31 08:45:20,724 DEBUG nullSafeSet() binding '2005-08-10 10:24:39' to parameter: 2 - org.hibernate.type.NullableType.nullSafeSet(NullableType.java:60)
2005-08-31 08:45:20,724 DEBUG nullSafeSet() binding '3000-01-01 00:00:00' to parameter: 3 - org.hibernate.type.NullableType.nullSafeSet(NullableType.java:60)
2005-08-31 08:45:20,724 DEBUG nullSafeSet() binding '2003-04-14 00:00:00' to parameter: 4 - org.hibernate.type.NullableType.nullSafeSet(NullableType.java:60)
2005-08-31 08:45:20,724 DEBUG nullSafeSet() binding '4028c0e3060b44a601060b44f86c0001' to parameter: 5 - org.hibernate.type.NullableType.nullSafeSet(NullableType.java:60)
2005-08-31 08:45:20,724 DEBUG nullSafeSet() binding null to parameter: 6 - org.hibernate.type.NullableType.nullSafeSet(NullableType.java:53)
2005-08-31 08:45:20,724 DEBUG nullSafeSet() binding '4028c0e3060b44a601060b45bf360004' to parameter: 7 - org.hibernate.type.NullableType.nullSafeSet(NullableType.java:60)
2005-08-31 08:45:20,724 DEBUG nullSafeSet() binding null to parameter: 8 - org.hibernate.type.NullableType.nullSafeSet(NullableType.java:53)
2005-08-31 08:45:20,724 DEBUG nullSafeSet() binding '4028c0e3060b44a601060b45c09d0007' to parameter: 9 - org.hibernate.type.NullableType.nullSafeSet(NullableType.java:60)
2005-08-31 08:45:20,724 DEBUG addToBatch() Adding to batch - org.hibernate.jdbc.BatchingBatcher.addToBatch(BatchingBatcher.java:28)
2005-08-31 08:45:20,724 DEBUG doExecuteBatch() Executing batch size: 1 - org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:55)
2005-08-31 08:45:20,724 DEBUG logClosePreparedStatement() about to close PreparedStatement (open PreparedStatements: 1, globally: 1) - org.hibernate.jdbc.AbstractBatcher.logClosePreparedStatement(AbstractBatcher.java:317)
2005-08-31 08:45:20,724 DEBUG closePreparedStatement() closing statement - org.hibernate.jdbc.AbstractBatcher.closePreparedStatement(AbstractBatcher.java:459)
2005-08-31 08:45:20,724 DEBUG logExceptions() could not update: [de.novasib.ttsib5.hbm.SYSADM5.Objektbez#4028c0e3060b44a601060b45c09d0007] [update SYSADM5.OBJEKTBEZ set FREMD_KLASSE=?, V_GUELTIG=?, B_GUELTIG=?, STAND=?, PROJEKT_ID=?, ENR_ID=?, TTSIB_OBJ_ID=?, FREMD_ID=? where ID=?] - org.hibernate.util.JDBCExceptionReporter.logExceptions(JDBCExceptionReporter.java:63)
java.sql.BatchUpdateException: failed batch
at org.hsqldb.jdbc.jdbcStatement.executeBatch(Unknown Source)
at org.hsqldb.jdbc.jdbcPreparedStatement.executeBatch(Unknown Source)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:58)
at org.hibernate.jdbc.BatchingBatcher.addToBatch(BatchingBatcher.java:34)
at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2187)
at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:2103)
at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2357)
at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:84)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:243)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:227)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:141)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:296)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:870)
Thanks,
Ender74.
|