|
| Problem | The SQL0532N A parent row cannot be deleted because the relationship "constraint-name" restricts the deletion exception can be issued under several circumstances. The example in this technote is a common one.
Assume entity bean Bean A mapped to database table Table A and entity bean Bean B mapped to table Table B. Table A has a foreign key reference to the primary key of Table B.
A SQL0532N can be issued because of the transaction attribute setting when data from Table B is removed. | | Cause | In this case a record is deleted from Table B by Bean B. This has the following two results:- The record containing the foreign key to the deleted record in Table B is removed from Table A. WebSphereŽ Application Server then performs an UPDATE to set the foreign key to null.
- WebSphere Application Server performs a DELETE for the record in Table B for Bean B.
If you attempt to delete a record from Table B, the DELETE in Table B occurs before the UPDATE. This leads to the SQL0532N exception because the foreign key constraint on Table B still exists. | | Solution | This problem is caused by using transaction attribute Required for the setForeignKey() method for table A instead of using the recommended transaction attribute of RequiresNew.
When the delete method is called, an attempt is made to remove the record from the database immediately. The UPDATE does not occur until after the transaction ends. Therefore, the operations are out of order.
The solution is to set the transaction attribute to RequiresNew, which, creates a new transaction and forces the update to occur before the delete. | |
| | |
| |
|
Product categories: Software, Application Servers, Distributed Application & Web Servers, WebSphere Application Server, EJB Container Operating system(s): AIX, HPUX, iSeries, Linux, Multi-Platform, Solaris, Windows Software version: 3.5, 4.0, 5.0, 5.1, 6.0 Software edition: Edition Independent Reference #: 1170802 IBM Group: Software Group Modified date: 2004-06-03
(C) Copyright IBM Corporation 2000, 2004. All Rights Reserved.
|