tags:

views:

25

answers:

2

I have two tables in my oracle database

Request and Approver. Every approver has a request. A foreign key protected by a constraint.

In my java code using kodo jdo 3.4 I call delete persistant on some or all of the approvers. Then at the end if no approvers are left I call delete persistant on the Request. When I commit I my integrity constraint fires because the sql is running in the wrong order I guess.

Is there a way to force the delete calls to the db to happen in a certain way?

I was also thinking of rolling back the transaction myself in the case where everything gets deleted and hand forcing the deletes in the correct order. But that seems like a hack.

Thanks

A: 

I think the problem is because you are deleting the Approvers in a transaction, and deleting Request in another. Try committing the transaction in which you deleted the Approvers.

Second thing you might want to do is to ALTER the Requesttable definition and define it with ON DELETE CASCADE, then you need not do it all by yourself. Not sure if there something, some requirement, is stopping you from doing in this way.

Adeel Ansari
A: 

Is JDO managing the relationship (for example, does Request have a Set field and specify the JDO "mapped-by" attribute), or are you setting the foreign key explicitly? If JDO is aware of the relationship, it should do the deletes in the right order.

Alternatively, if changing the JDO configuration is not an option, you could try calling the PersistenceManager's flush() method after deleting the Approvers. That should apply any outstanding deletes to the datastore (still within the transaction though).

Todd Owen
JDO is managing the relationships.Flush might work.
Aaron