cascade delete fail for EJB2 CMP Entities after migration to EAP6

Solution Verified - Updated

Environment

  • Red Hat JBoss Enterprise Application Platform (EAP)
    • 6.x

Issue

  • After migrate an EJB2 application from EAP4 or EAP5 to EAP6 we see issues during deletion of entities.
    If a relation is marked with cascade-delete it look like that the order of DELETE statements is not respected and therefore a database constraint is violated.
    Depend on the used database an Exception was shown, i.e.
Caused by: javax.ejb.RemoveException: JBAS010757: Could not remove 28dfa49b1835aae56b875a7680d56f43
Caused by: com.ibm.db2.jcc.am.SqlIntegrityConstraintViolationException: DB2 SQL Error: SQLCODE=-532, SQLSTATE=23504, 
  • Batch Cascade Delete is not working in JBoss EAP 6 as in Jboss AS 5.1
  • The jbosscmp-jdbc_4_1.dtd does not allow value true/false inside <batch-cascade-delete>, as it says it should be EMPTY.
<!ELEMENT batch-cascade-delete EMPTY>

Resolution

The flag for batch cascade delete needs to be set within the jbosscmp-jdbc.xml.

  <relationships>
    <ejb-relation>
      <ejb-relation-name>X_Y</ejb-relation-name>
      ...
      <batch-cascade-delete>true</batch-cascade-delete>
   ...

This is against the DTD and you must disable the validation. The EAP6 server will not validate the descriptor.

Note: when using this flag, it is mandatory to set cascade-delete within the ejb-jar.xml as well.

Root Cause

The default of the attribute batch-cascade-delete has changed in EAP6 from true to false.

Also the element within jbosscmp-jdbc.xml is is different to former EAP versions and not according to the jbosscmp-jdbc*.dtd,
the correct element is :

   <batch-cascade-delete/>

This is tracked by This content is not included.BZ 1215196

Components
Category

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.