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: Closed
>Resolution: Fixed
Priority: 5
Submitted By: Liam Magee (lmagee)
>Assigned to: Dain Sundstrom (dsundstrom)
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.



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

>Comment By: Dain Sundstrom (dsundstrom)
Date: 2001-11-04 07:00

Message:
Logged In: YES 
user_id=251431

It is required that the object on which remove was called 
is removed before remove is cascaded to any relationhsips.  
See section 10.3.4.2 Cascade-delete of the EJB 2.0 Final 
Draft for more info.

The code was removing the entity to be delete from all 
relationships by setting the fk fields to null, before 
executing the remove.  The problem was that the changes to 
the related entities were not synchronized with the 
database (i.e., no update statement was executed) before 
the remove was executed.

Note: this bug was fixed on 2001/08/07.

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

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

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

Reply via email to