Hi,
I'm rather new to hibernate and I have the following problem:
I have two tables: Actor and Profile. there's a one to many relationship between them. Cascading delete was set during database creation so that should be taken care by the DBMS.
But, when I try to delete an actor, Hibernate tries to update the profile table to set the actor_id to null, I can't understand why... Null values are not allowed for that field, so this is a problem. On 'easy' workaround would be to allow nulls for the field actor_id, but this is not acceptable :-(
Any suggestions would be greatly appreciated.
These are the mapping files used:
Actor.hbm.xml:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="com.ing.web.security.wsa.hibernate.Actor" table="actor"
dynamic-update="true" optimistic-lock="all">
<id name="id" column="id">
<generator class="assigned" />
</id>
<many-to-one name="state" column="state_id" not-null="true"/>
<many-to-one name="actorType" column="type_id" not-null="true"/>
<set name="profiles" lazy="true">
<key column="actor_id"/>
<one-to-many class="com.ing.web.security.wsa.hibernate.Profile"/>
</set>
<set name="smartCards" lazy="true">
<key column="actor_id"/>
<one-to-many class="com.ing.web.security.wsa.hibernate.SmartCard"/>
</set>
<set name="passWords" lazy="true">
<key column="actor_id"/>
<one-to-many class="com.ing.web.security.wsa.hibernate.Password"/>
</set>
</class>
</hibernate-mapping>
Profile.hbm.xml:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="com.ing.web.security.wsa.hibernate.Profile" table="profile"
dynamic-update="true" optimistic-lock="all">
<id name="id">
<generator class="assigned" />
</id>
<many-to-one name="profileType" column="profile_type_id" not-null="true"/>
<many-to-one name="state" column="state_id" not-null="true"/>
<property name="actorId" column="actor_id"/>
<property name="tssUserId" column="tss_user_id"/>
<property name="tssPassword" column="tss_password"/>
</class>
</hibernate-mapping>
To delete an actor, I try the following:
_session.delete(actor), where actor is the persistent object associated to the actor table.
The output of the exception after a deletion attempt looks as follows:
Hibernate: select actor0_.id as id2_, actor0_.state_id as state_id2_, actor0_.type_id as type_id2_, state1_.id as id0_, state1_.descr as descr0_, actortype2_.id as id1_, actortype2_.descr as descr1_ from actor actor0_, state state1_, actor_type actortype2_ where actor0_.id=? and actor0_.state_id=state1_.id(+) and actor0_.type_id=actortype2_.id(+)
<<<< actor's id: PIM00010
Hibernate: update profile set actor_id=null where actor_id=?
08/07/2004 10:07:20,798 WARN [main] com.ing.web.security.wsa.dao.WebLdapCredentialDAO - SQL Error: 1407, SQLState: 72000
08/07/2004 10:07:20,814 ERROR [main] com.ing.web.security.wsa.dao.WebLdapCredentialDAO - ORA-01407: cannot update ("WSA"."PROFILE"."ACTOR_ID") to NULL
08/07/2004 10:07:20,814 WARN [main] com.ing.web.security.wsa.dao.WebLdapCredentialDAO - SQL Error: 1407, SQLState: 72000
08/07/2004 10:07:20,814 ERROR [main] com.ing.web.security.wsa.dao.WebLdapCredentialDAO - ORA-01407: cannot update ("WSA"."PROFILE"."ACTOR_ID") to NULL
08/07/2004 10:07:20,861 ERROR [main] com.ing.web.security.wsa.dao.WebLdapCredentialDAO - Could not execute JDBC batch update
java.sql.SQLException: ORA-01407: cannot update ("WSA"."PROFILE"."ACTOR_ID") to NULL
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:168)
at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:208)
at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:543)
at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1405)
at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteFetch(TTC7Protocol.java:822)
at oracle.jdbc.driver.OracleStatement.executeNonQuery(OracleStatement.java:1446)
at oracle.jdbc.driver.OracleStatement.doExecuteOther(OracleStatement.java:1371)
at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:2883)
at com.mchange.v2.sql.filter.FilterPreparedStatement.executeBatch(FilterPreparedStatement.java:260)
at net.sf.hibernate.impl.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:54)
at net.sf.hibernate.impl.BatcherImpl.executeBatch(BatcherImpl.java:122)
at net.sf.hibernate.impl.BatcherImpl.prepareStatement(BatcherImpl.java:59)
at net.sf.hibernate.impl.BatcherImpl.prepareStatement(BatcherImpl.java:56)
at net.sf.hibernate.impl.BatcherImpl.prepareBatchStatement(BatcherImpl.java:109)
at net.sf.hibernate.collection.AbstractCollectionPersister.remove(AbstractCollectionPersister.java:482)
at net.sf.hibernate.impl.ScheduledCollectionRemove.execute(ScheduledCollectionRemove.java:22)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2414)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2369)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2236)
at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61)
at com.ing.web.security.wsa.dao.factory.base.WsaRdbDAOFactoryBase.commitTransaction(WsaRdbDAOFactoryBase.java:85)
at com.ing.web.security.wsa.facade.ActorFacade.deleteActor(ActorFacade.java:357)
at com.ing.web.security.wsa.facade.junit.ActorFacadeTest.testDeleteActor(ActorFacadeTest.java:114)
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 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)
08/07/2004 10:07:20,861 ERROR [main] com.ing.web.security.wsa.dao.WebLdapCredentialDAO - Could not synchronize database state with session
net.sf.hibernate.JDBCException: Could not execute JDBC batch update
at net.sf.hibernate.impl.BatcherImpl.executeBatch(BatcherImpl.java:129)
at net.sf.hibernate.impl.BatcherImpl.prepareStatement(BatcherImpl.java:59)
at net.sf.hibernate.impl.BatcherImpl.prepareStatement(BatcherImpl.java:56)
at net.sf.hibernate.impl.BatcherImpl.prepareBatchStatement(BatcherImpl.java:109)
at net.sf.hibernate.collection.AbstractCollectionPersister.remove(AbstractCollectionPersister.java:482)
at net.sf.hibernate.impl.ScheduledCollectionRemove.execute(ScheduledCollectionRemove.java:22)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2414)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2369)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2236)
at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61)
at com.ing.web.security.wsa.dao.factory.base.WsaRdbDAOFactoryBase.commitTransaction(WsaRdbDAOFactoryBase.java:85)
at com.ing.web.security.wsa.facade.ActorFacade.deleteActor(ActorFacade.java:357)
at com.ing.web.security.wsa.facade.junit.ActorFacadeTest.testDeleteActor(ActorFacadeTest.java:114)
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 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)
|