Bugs item #447158, was opened at 2001-08-02 12:42
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=376685&aid=447158&group_id=22866
Category: JBossCMP
Group: v3.0 Rabbit Hole
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: Adrian Price (adrianprice)
Date: 2003-01-24 16:58
Message:
Logged In: YES
user_id=580837
This bug has been fixed? I beg to differ. I have observed this
problem myself on JBoss 3.0.1 with Hypersonic SQLDB,
whilst attempting to use CMR cascade-delete. The database
schema I am using specifies foreign key constraints on the
owed entities.
It is not appropriate to null the FK fields (I can see that's
what's happening) if the <ejb-relationship-role> in ejb-jar.xml
contains the <cascade-delete/> element; instead, the
container must physically DELETE the related entities
BEFORE attempting to delete the owner entity, in the SAME
TRANSACTION, to avoid the database throwing a constraint
violation. This does not appear to be happening correctly.
Furthermore, the nulling of the owned entities' FKs appears
to be occurring in a different transaction, because afterwards
their FKs are null, and the owner entity is still present, its
remove() transaction having been rolled back on account of
the RemoveException throw because of the FK constraint
SQLException thrown by the database.
FYI: these same entity beans work just fine on WebLogic-
7.0, so I am confident that my application code and database
schema are correct.
----------------------------------------------------------------------
Comment By: Dain Sundstrom (dsundstrom)
Date: 2001-11-04 15: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:
https://sourceforge.net/tracker/?func=detail&atid=376685&aid=447158&group_id=22866
-------------------------------------------------------
This SF.NET email is sponsored by:
SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See!
http://www.vasoftware.com
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development