-->
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.  [ 3 posts ] 
Author Message
 Post subject: error deep-deleting entity with associations,failed update
PostPosted: Wed Aug 31, 2005 3:08 am 
Newbie

Joined: Wed Aug 31, 2005 2:29 am
Posts: 8
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.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 31, 2005 5:24 am 
Newbie

Joined: Wed Aug 31, 2005 2:29 am
Posts: 8
Hello again ;-),

I did de-activate the sql-batching for hibernate. Now i get a stacktrace, which confirms my suspicion about FREMD_ID being updated to null :

org.springframework.dao.DataIntegrityViolationException: Hibernate operation: could not update: [de.novasib.ttsib5.hbm.SYSADM5.Objektbez#4028c0e3060bd86a01060bd8c76a0007]; SQL [update SYSADM5.OBJEKTBEZ set FREMD_KLASSE=?, V_GUELTIG=?, B_GUELTIG=?, STAND=?, PROJEKT_ID=?, ENR_ID=?, TTSIB_OBJ_ID=?, FREMD_ID=? where ID=?]; Attempt to insert null into a non-nullable column: column: FREMD_ID table: OBJEKTBEZ in statement [update SYSADM5.OBJEKTBEZ set FREMD_KLASSE=?, V_GUELTIG=?, B_GUELTIG=?, STAND=?, PROJEKT_ID=?, ENR_ID=?, TTSIB_OBJ_ID=?, FREMD_ID=? where ID=?]; nested exception is java.sql.SQLException: Attempt to insert null into a non-nullable column: column: FREMD_ID table: OBJEKTBEZ in statement [update SYSADM5.OBJEKTBEZ set FREMD_KLASSE=?, V_GUELTIG=?, B_GUELTIG=?, STAND=?, PROJEKT_ID=?, ENR_ID=?, TTSIB_OBJ_ID=?, FREMD_ID=? where ID=?]
java.sql.SQLException: Attempt to insert null into a non-nullable column: column: FREMD_ID table: OBJEKTBEZ in statement [update SYSADM5.OBJEKTBEZ set FREMD_KLASSE=?, V_GUELTIG=?, B_GUELTIG=?, STAND=?, PROJEKT_ID=?, ENR_ID=?, TTSIB_OBJ_ID=?, FREMD_ID=? where ID=?]
at org.hsqldb.jdbc.Util.throwError(Unknown Source)
at org.hsqldb.jdbc.jdbcPreparedStatement.executeUpdate(Unknown Source)
at org.hibernate.jdbc.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:23)
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)
at org.springframework.orm.hibernate3.HibernateTemplate$27.doInHibernate(HibernateTemplate.java:713)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:312)
at org.springframework.orm.hibernate3.HibernateTemplate.flush(HibernateTemplate.java:711)
at de.novasib.test.ttsib5.AbstractTTSIB5DbTest.commit(AbstractTTSIB5DbTest.java:163)
at de.novasib.test.ttsib5.AbstractTTSIB5DbTest.tearDown(AbstractTTSIB5DbTest.java:128)
at de.novasib.test.ttsib5.ebff.impl.ProjektKillerImplTest.tearDown(ProjektKillerImplTest.java:102)
at junit.framework.TestCase.runBare(TestCase.java:130)
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:478)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)


Bye,
Ender74.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 31, 2005 6:03 am 
Newbie

Joined: Wed Aug 31, 2005 2:29 am
Posts: 8
Hi,

Okay, i found the solution. It is this little sentence from the reference guide :

Quote:
You may delete objects in any order you like, without risk of foreign key constraint violations. It is still possible
to violate a NOT NULL constraint on a foreign key column by deleting objects in the wrong order, e.g. if
you delete the parent, but forget to delete the children.


I have to change my delete Order to :

delete(objBez);
delete(objBez.getTeilnetz());

(although from the programmers view, i find it weird, to access the associated entity after deleting the "parent object". But from the relational view the parent ist Teilnetz and the child the objBez).

Thanks,
Ender74.


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

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.