Skip to content

Cascading deletion attempts to set a non-nullable column to null #14586

@joemccall86

Description

@joemccall86

Task List

  • Steps to reproduce provided
  • Stacktrace (if present) provided
  • Example that reproduces the problem uploaded to Github
  • Full description of the issue provided (see below)

Steps to Reproduce

  1. Create a parent domain object that aggregates two child domain objects, and one of those child domain object has the other child domain object as a property (https://github.com/joemccall86/cascade-delete-test/tree/master/grails-app/domain/cascade/delete/test)
  2. Populate the domain objects and attempt to delete the parent domain object
  3. Delete the object (force a flush to see the error immediately)

Expected Behaviour

The parent object is deleted, and deletions cascade onto the child objects

Actual Behaviour

The underlying database complains that a null value is being set for a non-nullable column. e.g.,:

org.h2.jdbc.JdbcSQLException: NULL not allowed for column "SELECTED_CHANNEL_ID"; SQL statement:
update person set version=?, name=?, organization_id=?, selected_channel_id=? where id=? and version=? [23502-194]

Stacktrace:

2018-02-20 16:10:06.995 ERROR --- [    Test worker] o.h.engine.jdbc.spi.SqlExceptionHelper   : NULL not allowed for column "SELECTED_CHANNEL_ID"; SQL statement:
update person set version=?, name=?, organization_id=?, selected_channel_id=? where id=? and version=? [23502-194]
cascade.delete.test.OrganizationSpec > organization deletions cascade FAILED
    org.springframework.dao.DataIntegrityViolationException at OrganizationSpec.groovy:29
        Caused by: org.h2.jdbc.JdbcSQLException at OrganizationSpec.groovy:29

Hibernate operation: could not execute statement; SQL [n/a]; NULL not allowed for column "SELECTED_CHANNEL_ID"; SQL statement:
update person set version=?, name=?, organization_id=?, selected_channel_id=? where id=? and version=? [23502-194]; nested exception is org.h2.jdbc.JdbcSQLException: NULL not allowed for column "SELECTED_CHANNEL_ID"; SQL statement:
update person set version=?, name=?, organization_id=?, selected_channel_id=? where id=? and version=? [23502-194]
org.springframework.dao.DataIntegrityViolationException: Hibernate operation: could not execute statement; SQL [n/a]; NULL not allowed for column "SELECTED_CHANNEL_ID"; SQL statement:
update person set version=?, name=?, organization_id=?, selected_channel_id=? where id=? and version=? [23502-194]; nested exception is org.h2.jdbc.JdbcSQLException: NULL not allowed for column "SELECTED_CHANNEL_ID"; SQL statement:
update person set version=?, name=?, organization_id=?, selected_channel_id=? where id=? and version=? [23502-194]
	at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:243)
	at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:73)
	at org.grails.orm.hibernate.GrailsHibernateTemplate.convertJdbcAccessException(GrailsHibernateTemplate.java:711)
	at org.grails.orm.hibernate.GrailsHibernateTemplate.convertHibernateAccessException(GrailsHibernateTemplate.java:699)
	at org.grails.orm.hibernate.GrailsHibernateTemplate.doExecute(GrailsHibernateTemplate.java:290)
	at org.grails.orm.hibernate.GrailsHibernateTemplate.execute(GrailsHibernateTemplate.java:230)
	at org.grails.orm.hibernate.GrailsHibernateTemplate.execute(GrailsHibernateTemplate.java:116)
	at org.grails.orm.hibernate.AbstractHibernateGormInstanceApi.delete(AbstractHibernateGormInstanceApi.groovy:193)
	at org.grails.datastore.gorm.GormEntity$Trait$Helper.delete(GormEntity.groovy:193)
	at cascade.delete.test.OrganizationSpec.$tt__$spock_feature_0_0(OrganizationSpec.groovy:29)
	at cascade.delete.test.OrganizationSpec.organization deletions cascade_closure1(OrganizationSpec.groovy)
	at groovy.lang.Closure.call(Closure.java:414)
	at groovy.lang.Closure.call(Closure.java:430)
	at grails.transaction.GrailsTransactionTemplate$1.doInTransaction(GrailsTransactionTemplate.groovy:70)
	at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:133)
	at grails.transaction.GrailsTransactionTemplate.executeAndRollback(GrailsTransactionTemplate.groovy:67)
	at cascade.delete.test.OrganizationSpec.organization deletions cascade(OrganizationSpec.groovy)
Caused by: org.h2.jdbc.JdbcSQLException: NULL not allowed for column "SELECTED_CHANNEL_ID"; SQL statement:
update person set version=?, name=?, organization_id=?, selected_channel_id=? where id=? and version=? [23502-194]
	at org.h2.message.DbException.getJdbcSQLException(DbException.java:345)
	at org.h2.message.DbException.get(DbException.java:179)
	at org.h2.message.DbException.get(DbException.java:155)
	at org.h2.table.Column.validateConvertUpdateSequence(Column.java:311)
	at org.h2.table.Table.validateConvertUpdateSequence(Table.java:793)
	at org.h2.command.dml.Update.update(Update.java:125)
	at org.h2.command.CommandContainer.update(CommandContainer.java:101)
	at org.h2.command.Command.executeUpdate(Command.java:258)
	at org.h2.jdbc.JdbcPreparedStatement.executeUpdateInternal(JdbcPreparedStatement.java:160)
	at org.h2.jdbc.JdbcPreparedStatement.executeUpdate(JdbcPreparedStatement.java:146)
	at org.apache.tomcat.jdbc.pool.StatementFacade$StatementProxy.invoke(StatementFacade.java:138)
	at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:204)
	at org.hibernate.engine.jdbc.batch.internal.NonBatchingBatch.addToBatch(NonBatchingBatch.java:45)
	at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:3132)
	at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:3011)
	at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:3391)
	at org.hibernate.action.internal.EntityUpdateAction.execute(EntityUpdateAction.java:145)
	at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:582)
	at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:456)
	at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:337)
	at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:39)
	at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1295)
	at org.grails.orm.hibernate.AbstractHibernateGormInstanceApi.delete_closure1(AbstractHibernateGormInstanceApi.groovy:196)
	at groovy.lang.Closure.call(Closure.java:414)
	at org.grails.orm.hibernate.GrailsHibernateTemplate.doExecute(GrailsHibernateTemplate.java:286)
	... 12 more

Environment Information

  • Operating System: Ubuntu MATE 17.10
  • GORM Version: 6.0.13.RELEASE
  • Grails Version (if using Grails): 3.2.12
  • JDK Version: openjdk version "1.8.0_162"

Example Application

Note

This issue does not appear in 6.1.8.RELEASE.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions