-->
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.  [ 1 post ] 
Author Message
 Post subject: How do I perform this delete with this many-to-many mapping?
PostPosted: Fri Jul 09, 2004 3:18 pm 
Newbie

Joined: Wed Jun 16, 2004 11:20 am
Posts: 6
I have class A which contains a list of objects of type class B

Class B can know nothing about class A.

With my mappings (below), everything works great when I add a b object to A's list.

But the problem is B objects can get deleted while still in A's list. If an attempt to delete a B object is made while it is in A's list, a referential integrity exception is thrown.

How can I set things up so that B objects can be deleted whether or not they are still in A's list? Please note I would like to avoid B having to know about A (eg. bidirectional mappings)

Thank you for your help.

Mappings:

B:


Code:
<class
        name="B"
        table="b"
        dynamic-update="false"
        dynamic-insert="false"  >

        <id name="id" type="UUIDType" >
                <column  name="b_id"  sql-type="char(36)"  />
                 ...etc...
        </id>

</class>



Class A (which contains a list of Bs):

Code:

<class
       name="A"
        table="a"
        dynamic-update="false"
        dynamic-insert="false"  >

        <id name="id" type="UUIDType" >
                <column  name="a_id"  sql-type="char(36)"  />
                 ...etc...
        </id>

        <list
            name="listOfB"
            table="b_maps"
            lazy="false"
            inverse="false"
            cascade="all-delete-orphan">

              <key>
                <column name="a_id"   sql-type="char(36)"  />
              </key>

              <index  column="list_index"  />

              <many-to-many
                  class="B"
                  outer-join="auto">
                   <column  name="b_id"  sql-type="char(36)"/>
               </many-to-many>
        </list>           

</class>



Ref integrity error:


Code:
10:56:18,975 ERROR [LogInterceptor] RuntimeException:
org.springframework.jdbc.UncategorizedSQLException: (SessionSynchronization): encountered SQLException [ERROR:  fkf6b4db9257bb23a8 referential integrity violation - key in incidents still referenced from incident_tracker_maps
]; nested exception is java.sql.SQLException: ERROR:  fkf6b4db9257bb23a8 referential integrity violation - key in incidents still referenced from incident_tracker_maps

java.sql.SQLException: ERROR:  fkf6b4db9257bb23a8 referential integrity violation - key in incidents still referenced from incident_tracker_maps

        at org.postgresql.core.QueryExecutor.execute(QueryExecutor.java:131)
        at org.postgresql.jdbc1.AbstractJdbc1Connection.ExecSQL(AbstractJdbc1Connection.java:505)
        at org.postgresql.jdbc1.AbstractJdbc1Statement.execute(AbstractJdbc1Statement.java:320)
        at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:48)
        at org.postgresql.jdbc1.AbstractJdbc1Statement.executeUpdate(AbstractJdbc1Statement.java:197)
        at org.jboss.resource.adapter.jdbc.WrappedPreparedStatement.executeUpdate(WrappedPreparedStatement.java:324)
        at net.sf.hibernate.persister.NormalizedEntityPersister.delete(NormalizedEntityPersister.java:609)
        at net.sf.hibernate.impl.ScheduledDeletion.execute(ScheduledDeletion.java:29)
        at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2382)
        at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2340)
        at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2204)
        at org.springframework.orm.hibernate.SessionFactoryUtils$SpringSessionSynchronization.beforeCommit(SessionFactoryUtils.java:378)
        at org.springframework.transaction.support.AbstractPlatformTransactionManager.triggerBeforeCommit(AbstractPlatformTransactionManager.java:435)
        at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:311)
        at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:189)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:138)
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:148)


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

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.