Bugs item #447158, was opened at 2001-08-02 05:42
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=376685&aid=447158&group_id=22866

Category: JBossCMP
Group: v2.5 Rabbit Hole (unstable)
Status: Open
Resolution: None
Priority: 5
Submitted By: Liam Magee (lmagee)
Assigned to: Nobody/Anonymous (nobody)
Summary: Problem with cascade-delete in CMP2.x

Initial Comment:
 In the JDBCRemoveEntityCommand, the deletion of the 
master record happens before any slave records. Is 
this correct? I get the following error when removing 
an EJB with relations:
 
javax.ejb.RemoveException: Could not remove 3
 at 
sun.rmi.transport.StreamRemoteCall.exceptionReceivedFro
mServer(StreamRemoteCall.java:245)
 at sun.rmi.transport.StreamRemoteCall.executeCall
(StreamRemoteCall.java:220)
 at sun.rmi.server.UnicastRef.invoke
(UnicastRef.java:122)
 at 
org.jboss.ejb.plugins.jrmp.server.JRMPContainerInvoker_
Stub.invoke(Unknown Source)
 at 
org.jboss.ejb.plugins.jrmp.interfaces.GenericProxy.invo
keContainer(GenericProxy.java:362)
 at 
org.jboss.ejb.plugins.jrmp.interfaces.EntityProxy.invok
e(EntityProxy.java:133)
 at $Proxy1.remove(Unknown Source)
 at com.jaccess.startup.ModelTest.<init>
(C:/factory/jaccess/src/com/jaccess/startup/ModelTest.j
ava:46)
 at com.jaccess.startup.ModelTest.main
(C:/factory/jaccess/src/com/jaccess/startup/ModelTest.j
ava:19)

 
The server log shows:
 
[CMP,DEBUG] Remove command executing: DELETE FROM 
PRODUCT WHERE PROD_ID=?

[CMP,DEBUG] Set parameter: index=1, jdbcType=INTEGER, 
value=3

[CMP,DEBUG] interbase.interclient.SQLException: 
[interclient][interbase] violation of FOREIGN KEY 
constraint "INTEG_50" on table "PROJECT"

It looks to me like records with the foreign key 
should be removed first, to preserve referential 
integrity, ie:


  for(int i=0; i<cmrFields.length; i++) {
   if(cmrFields[i].getMetaData().getRelatedRole
().isCascadeDelete()) {
    Object oldRelation = oldRelationMap.get(cmrFields
[i]);
    if(oldRelation instanceof Collection) {
     Iterator oldValues = ((Collection)
oldRelation).iterator();
     while(oldValues.hasNext()) {
      EJBLocalObject oldValue = (EJBLocalObject)
oldValues.next(); 
      oldValue.remove();
     }
    } else {
     EJBLocalObject oldValue = (EJBLocalObject)
oldRelation; 
     oldValue.remove();
    }
   }
  }

        try {
   jdbcExecute(context.getId());
  } catch (Exception e) {
   throw new RemoveException("Could not remove " + 
context.getId());
  }


I've compiled and run this on my test case and it 
works correctly.



----------------------------------------------------------------------

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=376685&aid=447158&group_id=22866

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to