When you make the COLOR_ID non null, then you are making the constraint mandatory inside the database, but the EJB specification does not have such a notion. When you remove the Color, the CMP nulls out the relationship in memory (as it should), but the constraint prevents this being persisted.
If you make the COLOR_ID column nullable, then you are allowing Cars to exist that have an unknown Color. When you remove a referenced Color, CMP is correctly removing the reference in the database preserving its integrity. By removing a referenced entity, you are actually asking for this to happen. Regards Jeremy /************************* * Jeremy Boynes * Partner * Core Developers Network *************************/ > -----Original Message----- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] Behalf Of Tim McNerney > Sent: Wednesday, June 18, 2003 2:19 PM > To: [EMAIL PROTECTED] > Subject: [JBoss-user] Unexpected behavior when when deleting "one" > entity in CMR 1-many rel > > > 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. > > I've found the same behavior in 3.2.1. > > Please reply to my email address in addition to the list. > > Thanks in advance. > > --Tim > > > > ------------------------------------------------------- > This SF.Net email is sponsored by: INetU > Attention Web Developers & Consultants: Become An INetU Hosting Partner. > Refer Dedicated Servers. We Manage Them. You Get 10% Monthly Commission! > INetU Dedicated Managed Hosting http://www.inetu.net/partner/index.php > _______________________________________________ > JBoss-user mailing list > [EMAIL PROTECTED] > https://lists.sourceforge.net/lists/listinfo/jboss-user > ------------------------------------------------------- This SF.Net email is sponsored by: INetU Attention Web Developers & Consultants: Become An INetU Hosting Partner. Refer Dedicated Servers. We Manage Them. You Get 10% Monthly Commission! INetU Dedicated Managed Hosting http://www.inetu.net/partner/index.php _______________________________________________ JBoss-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-user
