1 Reply Latest reply on Jun 18, 2003 5:19 PM by Tim McNerney

    Unexpected behavior when when deleting "one" entity in CMR 1

    Tim McNerney Newbie

      Using 3.0.7, I have two entity beans with a 1-to-many relationship defined. Using CMP & CMR. This is not a parent-child relationship, so there is no cascade set up.

      Let's call them Car and Color. A Car has a Color. A Color may be related to several Cars.

      If I try and delete a Color that some Car is referencing and the underlying database COLOR_ID field is set to not null, I get a constraint violation and the operation fails. This is what I'd expect.

      If the underlying database COLOR_ID field is set to null, the Color is deleted and the COLOR_ID field is set to null. This is not what I would expect.

      I read somewhere that JBoss CMP enforced integrity, but in this case it doesn't seem to be the case. Rather it seems to rely on the underlying database to support integrity by performing an action that I didn't think I was asking for, namely nulling out the COLOR_ID field of all Car entries referring to the Color I'm deleting, with failure determined by the database's response.

      Is there some way to get JBoss CMP/CMR to enforce integrity at its level so that if I try and delete a Color still accessed by a Car I get an exception? Alternatively, is there a way to tell it not to try and null out the COLOR_ID fields in the Cars, so that it would get the exception from the DB?

      This is a general problem we're running into, so I'd prefer a general solution that modifies the behavior of CMP, rather than having to change some settings for each relationship I want to behave in this manor. And I know I can check this by hand, but that is not the solution I'm hoping for.

      Thanks in advance.

      --Tim