Hi,
I'm having problems to delete objects from a collection (on-to-many).
I'm using oracle 9i... for inserts work fine.
Like this:
//remove senha from Usuario
this.getSenhas().remove(resSenha);
My mapping:
(Usuario)
<hibernate-mapping>
<class
name="br.trib.seg.persistencia.Usuario"
table="SEGUSUUSUARIO"
>
<id
unsaved-value="0"
name="idfUsuario"
type="long"
column="IDF_USUARIO"
>
<generator class="native">
<param name="sequence">SEQ_SEGUSU1</param>
</generator>
</id>
<property
name="numDiasExpiracao"
type="long"
column="NUM_DIAS_EXPIRACAO"
length="10"
/>
<!-- associations -->
<bag
name="senhas"
lazy="true"
inverse="false"
cascade="all-delete-orphan"
>
<key>
<column name="IDF_USUARIO" />
</key>
<one-to-many
class="br.trib.seg.persistencia.UsuarioSenha"
/>
</bag>
</class>
</hibernate-mapping>
My other mapping:
(Senha)
<hibernate-mapping>
<class
name="br.trib.seg.persistencia.UsuarioSenha"
table="SEGUSSUSUARIO_SENHA"
>
<id
unsaved-value="0"
name="idfUsuarioSenha"
type="long"
column="IDF_USUARIO_SENHA"
>
<generator class="native">
<param name="sequence">SEQ_SEGUSS1</param>
</generator>
</id>
<property
name="dtaExpiracao"
type="java.sql.Timestamp"
column="DTA_EXPIRACAO"
length="7"
/>
<!-- associations -->
<many-to-one
name="usuario"
class="br.trib.seg.persistencia.Usuario"
not-null="true"
>
<column name="IDF_USUARIO" />
</many-to-one>
</class>
</hibernate-mapping>
My stack trace:
17:08:44,173 INFO SessionFactoryObjectFactory:82 - no JNDI name configured
Hibernate: select usuario0_.IDF_USUARIO as IDF_USUA1_1_, usuario0_.NME_LOGIN as NME_LOGIN1_, usuario0_.NME_USUARIO as NME_USUA3_1_, usuario0_.DES_EMAIL as DES_EMAIL1_, usuario0_.STA_USUARIO as STA_USUA5_1_, usuario0_.NUM_DIAS_EXPIRACAO as NUM_DIAS6_1_, usuario0_.QTD_SENHA_ANTERIOR as QTD_SENH7_1_, usuario0_.DTA_CADASTRO as DTA_CADA8_1_, usuario0_.IDF_LOTACAO as IDF_LOTA9_1_, lotacao1_.IDF_LOTACAO as IDF_LOTA1_0_, lotacao1_.NME_SIGLA as NME_SIGLA0_, lotacao1_.NME_LOTACAO as NME_LOTA3_0_, lotacao1_.NUM_TELEFONE as NUM_TELE4_0_, lotacao1_.NME_RUA as NME_RUA0_, lotacao1_.NUM_RUA as NUM_RUA0_, lotacao1_.DES_COMPLEMENTO as DES_COMP7_0_, lotacao1_.DES_BAIRRO as DES_BAIRRO0_, lotacao1_.DES_CEP as DES_CEP0_, lotacao1_.NME_CIDADE as NME_CIDADE0_, lotacao1_.NME_UF as NME_UF0_, lotacao1_.NME_PAIS as NME_PAIS0_, lotacao1_.DTA_CADASTRO as DTA_CAD13_0_ from SEGUSUUSUARIO usuario0_, SEGLOTLOTACAO lotacao1_ where usuario0_.IDF_USUARIO=? and usuario0_.IDF_LOTACAO=lotacao1_.IDF_LOTACAO(+)
Hibernate: select senhas0_.IDF_USUARIO_SENHA as IDF_USUA1___, senhas0_.IDF_USUARIO as IDF_USUA4___, senhas0_.IDF_USUARIO_SENHA as IDF_USUA1_0_, senhas0_.DES_SENHA as DES_SENHA0_, senhas0_.DTA_EXPIRACAO as DTA_EXPI3_0_, senhas0_.IDF_USUARIO as IDF_USUA4_0_ from SEGUSSUSUARIO_SENHA senhas0_ where senhas0_.IDF_USUARIO=?
Hibernate: select usuario0_.IDF_USUARIO as IDF_USUA1_, usuario0_.NME_LOGIN as NME_LOGIN, usuario0_.NME_USUARIO as NME_USUA3_, usuario0_.DES_EMAIL as DES_EMAIL, usuario0_.STA_USUARIO as STA_USUA5_, usuario0_.NUM_DIAS_EXPIRACAO as NUM_DIAS6_, usuario0_.QTD_SENHA_ANTERIOR as QTD_SENH7_, usuario0_.DTA_CADASTRO as DTA_CADA8_, usuario0_.IDF_LOTACAO as IDF_LOTA9_ from SEGUSUUSUARIO usuario0_ where (upper(usuario0_.NME_LOGIN)=upper(?))
Hibernate: select SEQ_SEGUSS1.nextval from dual
Hibernate: select usuario0_.IDF_USUARIO as IDF_USUA1_1_, usuario0_.NME_LOGIN as NME_LOGIN1_, usuario0_.NME_USUARIO as NME_USUA3_1_, usuario0_.DES_EMAIL as DES_EMAIL1_, usuario0_.STA_USUARIO as STA_USUA5_1_, usuario0_.NUM_DIAS_EXPIRACAO as NUM_DIAS6_1_, usuario0_.QTD_SENHA_ANTERIOR as QTD_SENH7_1_, usuario0_.DTA_CADASTRO as DTA_CADA8_1_, usuario0_.IDF_LOTACAO as IDF_LOTA9_1_, lotacao1_.IDF_LOTACAO as IDF_LOTA1_0_, lotacao1_.NME_SIGLA as NME_SIGLA0_, lotacao1_.NME_LOTACAO as NME_LOTA3_0_, lotacao1_.NUM_TELEFONE as NUM_TELE4_0_, lotacao1_.NME_RUA as NME_RUA0_, lotacao1_.NUM_RUA as NUM_RUA0_, lotacao1_.DES_COMPLEMENTO as DES_COMP7_0_, lotacao1_.DES_BAIRRO as DES_BAIRRO0_, lotacao1_.DES_CEP as DES_CEP0_, lotacao1_.NME_CIDADE as NME_CIDADE0_, lotacao1_.NME_UF as NME_UF0_, lotacao1_.NME_PAIS as NME_PAIS0_, lotacao1_.DTA_CADASTRO as DTA_CAD13_0_ from SEGUSUUSUARIO usuario0_, SEGLOTLOTACAO lotacao1_ where usuario0_.IDF_USUARIO=? and usuario0_.IDF_LOTACAO=lotacao1_.IDF_LOTACAO(+)
Hibernate: select recurso0_.IDF_RECURSO as IDF_RECU1_0_, recurso0_.IND_TIPO_RECURSO as IND_TIPO2_0_, recurso0_.NME_RECURSO as NME_RECU3_0_, recurso0_.DTA_CADASTRO as DTA_CADA4_0_, recurso0_.NME_SIGLA as NME_SIGLA0_, recurso0_.DES_RECURSO as DES_RECU6_0_, recurso0_.STA_RECURSO as STA_RECU7_0_, recurso0_.IND_REG_ACESSO_PROG as IND_REG_8_0_, recurso0_.DES_URL as DES_URL0_ from SEGRECRECURSO recurso0_ where recurso0_.IDF_RECURSO=?
Hibernate: insert into SEGUSSUSUARIO_SENHA (DES_SENHA, DTA_EXPIRACAO, IDF_USUARIO, IDF_USUARIO_SENHA) values (?, ?, ?, ?)
Hibernate: update SEGUSSUSUARIO_SENHA set DES_SENHA=?, DTA_EXPIRACAO=?, IDF_USUARIO=? where IDF_USUARIO_SENHA=?
Hibernate: update SEGUSSUSUARIO_SENHA set IDF_USUARIO=null where IDF_USUARIO=? and IDF_USUARIO_SENHA=?
17:08:44,623 WARN JDBCExceptionReporter:38 - SQL Error: 1407, SQLState: 72000
17:08:44,623 ERROR JDBCExceptionReporter:46 - ORA-01407: cannot update ("SIMTDESENV"."SEGUSSUSUARIO_SENHA"."IDF_USUARIO") to NULL
17:08:44,623 ERROR JDBCExceptionReporter:38 - could not delete collection rows: [br.trib.seg.persistencia.Usuario.senhas#3]
java.sql.SQLException: ORA-01407: cannot update ("SIMTDESENV"."SEGUSSUSUARIO_SENHA"."IDF_USUARIO") to NULL
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:289)
at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:573)
at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1891)
at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteFetch(TTC7Protocol.java:1093)
at oracle.jdbc.driver.OracleStatement.executeNonQuery(OracleStatement.java:2047)
at oracle.jdbc.driver.OracleStatement.doExecuteOther(OracleStatement.java:1940)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:2709)
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:589)
at net.sf.hibernate.impl.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:22)
at net.sf.hibernate.collection.AbstractCollectionPersister.deleteRows(AbstractCollectionPersister.java:580)
at net.sf.hibernate.impl.ScheduledCollectionUpdate.execute(ScheduledCollectionUpdate.java:47)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2382)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2338)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2204)
at br.trib.seg.teste.app.abstractfactory.AbstractFactoryHibernateImpl.atualizar(AbstractFactoryHibernateImpl.java:60)
at br.trib.seg.negocio.UsuarioFactoryImpl.alterar(UsuarioFactoryImpl.java:511)
at br.trib.seg.servico.SegFacadeImpl.alterarUsuario(SegFacadeImpl.java:162)
at br.trib.seg.teste.MudarSenhaTest.testMudarSenha(MudarSenhaTest.java:40)
at java.lang.reflect.Method.invoke(Native Method)
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:392)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:276)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:167)
17:08:44,633 ERROR SessionImpl:2343 - Could not synchronize database state with session
net.sf.hibernate.JDBCException: could not delete collection rows: [br.trib.seg.persistencia.Usuario.senhas#3]
at net.sf.hibernate.collection.AbstractCollectionPersister.deleteRows(AbstractCollectionPersister.java:596)
at net.sf.hibernate.impl.ScheduledCollectionUpdate.execute(ScheduledCollectionUpdate.java:47)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2382)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2338)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2204)
at br.trib.seg.teste.app.abstractfactory.AbstractFactoryHibernateImpl.atualizar(AbstractFactoryHibernateImpl.java:60)
at br.trib.seg.negocio.UsuarioFactoryImpl.alterar(UsuarioFactoryImpl.java:511)
at br.trib.seg.servico.SegFacadeImpl.alterarUsuario(SegFacadeImpl.java:162)
at br.trib.seg.teste.MudarSenhaTest.testMudarSenha(MudarSenhaTest.java:40)
at java.lang.reflect.Method.invoke(Native Method)
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:392)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:276)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:167)
Caused by:
java.sql.SQLException: ORA-01407: cannot update ("SIMTDESENV"."SEGUSSUSUARIO_SENHA"."IDF_USUARIO") to NULL
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:289)
at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:573)
at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1891)
at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteFetch(TTC7Protocol.java:1093)
at oracle.jdbc.driver.OracleStatement.executeNonQuery(OracleStatement.java:2047)
at oracle.jdbc.driver.OracleStatement.doExecuteOther(OracleStatement.java:1940)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:2709)
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:589)
at net.sf.hibernate.impl.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:22)
at net.sf.hibernate.collection.AbstractCollectionPersister.deleteRows(AbstractCollectionPersister.java:580)
... 20 more
Thanks.
_________________ Ricardo K. Costa
|