Hello there! I have a class (PlanoCobertura) which has a set with cascade=none set. When removing this entity, hibernate ignores my selection and tries to update the reference table for the collection setting the FK to null. Why is that?
Hibernate version:
2.1.6
Mapping documents:
Full stack trace of any exception that occurs:
16:20:22,722 DEBUG [SessionImpl] opened session
16:20:22,738 DEBUG [JDBCTransaction] begin
16:20:22,738 DEBUG [DriverManagerConnectionProvider] total checked-out connections: 0
16:20:22,738 DEBUG [DriverManagerConnectionProvider] using pooled JDBC connection, pool size: 0
16:20:22,738 DEBUG [JDBCTransaction] current autocommit status:false
16:20:22,738 DEBUG [SessionImpl] deleting a transient instance
16:20:22,785 DEBUG [SessionImpl] deleting [com.araujo.convenios.model.persistence.planocobertura.PlanoCobertura#109]
16:20:22,785 DEBUG [Cascades] processing cascades for: com.araujo.convenios.model.persistence.planocobertura.PlanoCobertura
16:20:22,800 DEBUG [Cascades] cascading to collection: com.araujo.convenios.model.persistence.planocobertura.PlanoCobertura.regraDiferenciacaoLocalPagto
16:20:22,800 DEBUG [SessionImpl] initializing collection [com.araujo.convenios.model.persistence.planocobertura.PlanoCobertura.regraDiferenciacaoLocalPagto#109]
16:20:22,800 DEBUG [SessionImpl] checking second-level cache
16:20:22,800 DEBUG [SessionImpl] collection not cached
16:20:22,800 DEBUG [BatcherImpl] about to open: 0 open PreparedStatements, 0 open ResultSets
16:20:22,800 DEBUG [SQL] select regradifer0_.PLAN_CD_PLANO as PLAN_CD14___, regradifer0_.RECO_CD_REGRA as RECO_CD_1___, regradifer0_.RECO_CD_REGRA as RECO_CD_1_0_, regradifer0_.XXXX_DH_ALT as XXXX_DH_2_0_, regradifer0_.RECO_DS_REGRA as RECO_DS_3_0_, regradifer0_.RECO_FL_DOMINGO as RECO_FL_4_0_, regradifer0_.RECO_FL_FERIADO as RECO_FL_5_0_, regradifer0_.RECO_VL_PCT_PG_VISTA as RECO_VL_6_0_, regradifer0_.RECO_FL_QUARTA as RECO_FL_7_0_, regradifer0_.RECO_FL_QUINTA as RECO_FL_8_0_, regradifer0_.RECO_FL_SABADO as RECO_FL_9_0_, regradifer0_.RECO_FL_SEGUNDA as RECO_FL10_0_, regradifer0_.RECO_FL_SEXTA as RECO_FL11_0_, regradifer0_.RECO_FL_TERCA as RECO_FL12_0_, regradifer0_.RECO_TP_VIDA as RECO_TP13_0_, regradifer0_.PLAN_CD_PLANO as PLAN_CD14_0_, regradifer0_.XXXX_CD_USUALT as XXXX_CD15_0_, regradifer0_.XXXX_CT_LOCK as XXXX_CT16_0_ from REGRA_LOC_PAGAMENTO regradifer0_ where regradifer0_.PLAN_CD_PLANO=?
Hibernate: select regradifer0_.PLAN_CD_PLANO as PLAN_CD14___, regradifer0_.RECO_CD_REGRA as RECO_CD_1___, regradifer0_.RECO_CD_REGRA as RECO_CD_1_0_, regradifer0_.XXXX_DH_ALT as XXXX_DH_2_0_, regradifer0_.RECO_DS_REGRA as RECO_DS_3_0_, regradifer0_.RECO_FL_DOMINGO as RECO_FL_4_0_, regradifer0_.RECO_FL_FERIADO as RECO_FL_5_0_, regradifer0_.RECO_VL_PCT_PG_VISTA as RECO_VL_6_0_, regradifer0_.RECO_FL_QUARTA as RECO_FL_7_0_, regradifer0_.RECO_FL_QUINTA as RECO_FL_8_0_, regradifer0_.RECO_FL_SABADO as RECO_FL_9_0_, regradifer0_.RECO_FL_SEGUNDA as RECO_FL10_0_, regradifer0_.RECO_FL_SEXTA as RECO_FL11_0_, regradifer0_.RECO_FL_TERCA as RECO_FL12_0_, regradifer0_.RECO_TP_VIDA as RECO_TP13_0_, regradifer0_.PLAN_CD_PLANO as PLAN_CD14_0_, regradifer0_.XXXX_CD_USUALT as XXXX_CD15_0_, regradifer0_.XXXX_CT_LOCK as XXXX_CT16_0_ from REGRA_LOC_PAGAMENTO regradifer0_ where regradifer0_.PLAN_CD_PLANO=?
16:20:22,800 DEBUG [BatcherImpl] preparing statement
16:20:22,816 DEBUG [IntegerType] binding '109' to parameter: 1
16:20:22,816 DEBUG [Loader] result set contains (possibly empty) collection: [com.araujo.convenios.model.persistence.planocobertura.PlanoCobertura.regraDiferenciacaoLocalPagto#109]
16:20:22,816 DEBUG [SessionImpl] uninitialized collection: initializing
16:20:22,816 DEBUG [Loader] processing result set
16:20:22,816 DEBUG [Loader] done processing result set (0 rows)
16:20:22,816 DEBUG [BatcherImpl] done closing: 0 open PreparedStatements, 0 open ResultSets
16:20:22,816 DEBUG [BatcherImpl] closing statement
16:20:22,816 DEBUG [Loader] total objects hydrated: 0
16:20:22,816 DEBUG [SessionImpl] 1 collections were found in result set
16:20:22,816 DEBUG [SessionImpl] collection fully initialized: [com.araujo.convenios.model.persistence.planocobertura.PlanoCobertura.regraDiferenciacaoLocalPagto#109]
16:20:22,816 DEBUG [SessionImpl] 1 collections initialized
16:20:22,816 DEBUG [SessionImpl] initializing non-lazy collections
16:20:22,832 DEBUG [SessionImpl] collection initialized
16:20:22,832 DEBUG [Cascades] done processing cascades for: com.araujo.convenios.model.persistence.planocobertura.PlanoCobertura
16:20:22,832 DEBUG [Cascades] version unsaved-value strategy UNDEFINED
16:20:22,832 DEBUG [Cascades] id unsaved-value strategy NULL
16:20:22,847 DEBUG [Cascades] processing cascades for: com.araujo.convenios.model.persistence.planocobertura.PlanoCobertura
16:20:22,847 DEBUG [Cascades] done processing cascades for: com.araujo.convenios.model.persistence.planocobertura.PlanoCobertura
16:20:22,847 DEBUG [JDBCTransaction] commit
16:20:22,847 DEBUG [SessionImpl] flushing session
16:20:22,847 DEBUG [SessionImpl] Flushing entities and processing referenced collections
16:20:22,863 DEBUG [SessionImpl] Processing unreferenced collections
16:20:22,863 DEBUG [SessionImpl] Collection dereferenced: [com.araujo.convenios.model.persistence.planocobertura.PlanoCobertura.regraCobrancaCartao#109]
16:20:22,863 DEBUG [SessionImpl] Collection dereferenced: [com.araujo.convenios.model.persistence.planocobertura.PlanoCobertura.regraDiferenciacaoLocalPagto#109]
16:20:22,863 DEBUG [SessionImpl] Collection dereferenced: [com.araujo.convenios.model.persistence.planocobertura.PlanoCobertura.vidas#109]
16:20:22,863 DEBUG [SessionImpl] Scheduling collection removes/(re)creates/updates
16:20:22,894 DEBUG [SessionImpl] Flushed: 0 insertions, 0 updates, 1 deletions to 1 objects
16:20:22,894 DEBUG [SessionImpl] Flushed: 0 (re)creations, 0 updates, 3 removals to 3 collections
16:20:22,894 DEBUG [Printer] listing entities:
16:20:22,910 DEBUG [Printer] com.araujo.convenios.model.persistence.planocobertura.PlanoCobertura{aplicarMenorPreco=Não, codUsuarioAlteracao=null, valorSubisidioTaxaEntrega=10.0, dataInicioOperacao=null, permiteCompraDrogatel=Sim, vidas=uninitialized, regraCompra=null, regraCobrancaCartao=uninitialized, porcentagemSubsidioCredenciado=null, regraDiferenciacaoLocalPagto=[], porcentagemSubsidioNaoCredenciado=null, somenteReceitaCredenciado=Não, dataAlteracao=2005-05-17 14:30:19, lock=null, dataDesativacao=null, limitePreAutorizacao=null, empresa=Empresa#1, descricao=Plano de teste de remoção, subsidioPrescritorCredenciado=Não, situacao=Inativo, abateSaldoQuantidade=Não, abateSaldoFinanceiro=Não, codigo=109, pagamentoAVista=null}
16:20:22,910 DEBUG [SessionImpl] executing flush
16:20:22,910 DEBUG [BasicCollectionPersister] Deleting collection: [com.araujo.convenios.model.persistence.planocobertura.PlanoCobertura.regraCobrancaCartao#109]
16:20:22,910 DEBUG [BatcherImpl] about to open: 0 open PreparedStatements, 0 open ResultSets
16:20:22,910 DEBUG [SQL] update REGRA_COBR_CARTAO set PLAN_CD_PLANO=null where PLAN_CD_PLANO=?
Hibernate: update REGRA_COBR_CARTAO set PLAN_CD_PLANO=null where PLAN_CD_PLANO=?
16:20:22,910 DEBUG [BatcherImpl] preparing statement
16:20:22,910 DEBUG [IntegerType] binding '109' to parameter: 1
16:20:22,910 DEBUG [BatcherImpl] done closing: 0 open PreparedStatements, 0 open ResultSets
16:20:22,910 DEBUG [BatcherImpl] closing statement
16:20:22,941 DEBUG [JDBCExceptionReporter] SQL Exception
java.sql.SQLException: Cannot insert the value NULL into column 'PLAN_CD_PLANO', table 'COMOS.dbo.REGRA_COBR_CARTAO'; column does not allow nulls. UPDATE fails.
at net.sourceforge.jtds.jdbc.SQLDiagnostic.addDiagnostic(SQLDiagnostic.java:364)
at net.sourceforge.jtds.jdbc.TdsCore.tdsErrorToken(TdsCore.java:2708)
at net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:2150)
at net.sourceforge.jtds.jdbc.TdsCore.getMoreResults(TdsCore.java:587)
at net.sourceforge.jtds.jdbc.JtdsStatement.processResults(JtdsStatement.java:438)
at net.sourceforge.jtds.jdbc.JtdsStatement.executeSQL(JtdsStatement.java:421)
at net.sourceforge.jtds.jdbc.JtdsPreparedStatement.executeUpdate(JtdsPreparedStatement.java:397)
at net.sf.hibernate.impl.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:22)
at net.sf.hibernate.collection.AbstractCollectionPersister.remove(AbstractCollectionPersister.java:486)
at net.sf.hibernate.impl.ScheduledCollectionRemove.execute(ScheduledCollectionRemove.java:22)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2418)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2373)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2240)
at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61)
at com.araujo.convenios.util.dao.HibernateUtil.commitTransaction(HibernateUtil.java:94)
at com.araujo.convenios.util.dao.HibernateDAO.commitTransaction(HibernateDAO.java:147)
at com.araujo.convenios.util.dao.HibernateDAO.delete(HibernateDAO.java:94)
at com.araujo.convenios.eai.dao.test.planocobertura.HibernatePlanoCoberturaDAOTest.testInsercaoRemocao(HibernatePlanoCoberturaDAOTest.java:233)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
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)
16:20:22,957 WARN [JDBCExceptionReporter] SQL Error: 515, SQLState: 23000
16:20:22,957 ERROR [JDBCExceptionReporter] Cannot insert the value NULL into column 'PLAN_CD_PLANO', table 'COMOS.dbo.REGRA_COBR_CARTAO'; column does not allow nulls. UPDATE fails.
16:20:22,957 ERROR [JDBCExceptionReporter] could not delete collection: [com.araujo.convenios.model.persistence.planocobertura.PlanoCobertura.regraCobrancaCartao#109]
java.sql.SQLException: Cannot insert the value NULL into column 'PLAN_CD_PLANO', table 'COMOS.dbo.REGRA_COBR_CARTAO'; column does not allow nulls. UPDATE fails.
at net.sourceforge.jtds.jdbc.SQLDiagnostic.addDiagnostic(SQLDiagnostic.java:364)
at net.sourceforge.jtds.jdbc.TdsCore.tdsErrorToken(TdsCore.java:2708)
at net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:2150)
at net.sourceforge.jtds.jdbc.TdsCore.getMoreResults(TdsCore.java:587)
at net.sourceforge.jtds.jdbc.JtdsStatement.processResults(JtdsStatement.java:438)
at net.sourceforge.jtds.jdbc.JtdsStatement.executeSQL(JtdsStatement.java:421)
at net.sourceforge.jtds.jdbc.JtdsPreparedStatement.executeUpdate(JtdsPreparedStatement.java:397)
at net.sf.hibernate.impl.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:22)
at net.sf.hibernate.collection.AbstractCollectionPersister.remove(AbstractCollectionPersister.java:486)
at net.sf.hibernate.impl.ScheduledCollectionRemove.execute(ScheduledCollectionRemove.java:22)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2418)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2373)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2240)
at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61)
at com.araujo.convenios.util.dao.HibernateUtil.commitTransaction(HibernateUtil.java:94)
at com.araujo.convenios.util.dao.HibernateDAO.commitTransaction(HibernateDAO.java:147)
at com.araujo.convenios.util.dao.HibernateDAO.delete(HibernateDAO.java:94)
at com.araujo.convenios.eai.dao.test.planocobertura.HibernatePlanoCoberturaDAOTest.testInsercaoRemocao(HibernatePlanoCoberturaDAOTest.java:233)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
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)
16:20:22,972 ERROR [SessionImpl] Could not synchronize database state with session
net.sf.hibernate.JDBCException: could not delete collection: [com.araujo.convenios.model.persistence.planocobertura.PlanoCobertura.regraCobrancaCartao#109]
at net.sf.hibernate.collection.AbstractCollectionPersister.remove(AbstractCollectionPersister.java:496)
at net.sf.hibernate.impl.ScheduledCollectionRemove.execute(ScheduledCollectionRemove.java:22)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2418)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2373)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2240)
at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61)
at com.araujo.convenios.util.dao.HibernateUtil.commitTransaction(HibernateUtil.java:94)
at com.araujo.convenios.util.dao.HibernateDAO.commitTransaction(HibernateDAO.java:147)
at com.araujo.convenios.util.dao.HibernateDAO.delete(HibernateDAO.java:94)
at com.araujo.convenios.eai.dao.test.planocobertura.HibernatePlanoCoberturaDAOTest.testInsercaoRemocao(HibernatePlanoCoberturaDAOTest.java:233)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
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 insert the value NULL into column 'PLAN_CD_PLANO', table 'COMOS.dbo.REGRA_COBR_CARTAO'; column does not allow nulls. UPDATE fails.
at net.sourceforge.jtds.jdbc.SQLDiagnostic.addDiagnostic(SQLDiagnostic.java:364)
at net.sourceforge.jtds.jdbc.TdsCore.tdsErrorToken(TdsCore.java:2708)
at net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:2150)
at net.sourceforge.jtds.jdbc.TdsCore.getMoreResults(TdsCore.java:587)
at net.sourceforge.jtds.jdbc.JtdsStatement.processResults(JtdsStatement.java:438)
at net.sourceforge.jtds.jdbc.JtdsStatement.executeSQL(JtdsStatement.java:421)
at net.sourceforge.jtds.jdbc.JtdsPreparedStatement.executeUpdate(JtdsPreparedStatement.java:397)
at net.sf.hibernate.impl.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:22)
at net.sf.hibernate.collection.AbstractCollectionPersister.remove(AbstractCollectionPersister.java:486)
... 24 more
16:20:23,003 DEBUG [JDBCTransaction] rollback
16:20:23,003 DEBUG [SessionImpl] transaction completion
16:20:23,003 DEBUG [SessionImpl] closing session
16:20:23,019 DEBUG [SessionImpl] disconnecting session
16:20:23,019 DEBUG [DriverManagerConnectionProvider] returning connection to pool, pool size: 1
16:20:23,019 DEBUG [SessionImpl] transaction completion
|