EJB CMP 2.0 and Referential Integrity. 2004-11-01 - By Naik, Vikram ( eBiz Mumbai )
Back Hi Markus, Thanks for your response. Yes, container does nullify the foreign key column(s) in Entity A. Now my question is, say we want to restrict the deletion of B, as its being refernced by Entity A. Currently we achieve that using the foreign key constraint at database level. For such relations we define, foreign key constraints which restricts the deletion on an entity as its being referenced. So are there any other ways to do so. If contianer can handle cascade delete, shouldn't it be able to handle such similar constraints ?? Vikram.
-- --Original Message-- -- From: Markus Fuchs [mailto:Markus.Fuchs@(protected)] Sent: Mon 11/1/2004 4:24 AM To: J2EE-INTEREST@(protected) Cc: Subject: Re: EJB CMP 2.0 and Referential Integrity.
"Having a Many To One relationship between A and B means that the foreign key must be defined in B's table" It's actually the other way round: Having a Many-To-One relationship between A and B means that the foreign key column(s) are defined in A's table. Removing B must automatically nullify A's foreign key column(s). The container guarantees this behavior, even for one-way relationships. -- markus. Markus Fuchs wrote: > Hi Vikram, > > Having a Many To One relationship between A and B means that the foreign key must be defined in B's table, so removing Entity B has no effect on A's representation in the database. The EJB Spec. defines relationships to be > "managed", i.e. the container must remove Entity B from the relationship to Entity A in memory. (See for instance EJB 2.1 Spec, sec. 10.3.7.5). > > B's cascadeDelete setting or foreign keys in the database have no influence on this behavior. The container will handle the described situation automatically. > > Regards, > > -- markus. > > "Naik, Vikram ( eBiz Mumbai )" wrote: > > > Thanks for your response. > > > > Thats, true container does take care of cascade delete, but what happens in the following scenario: > > > > Say we have a Many to One aggregate uni-directional CMR relation between Entity A and Entity B. > > > > Now, if we try to delete Entity B which is still be referred/ referenced by Entity A, the container just deletes the Entity B. unless we define a foreign key constraint at database level, that would restrict the deletion. > > > > Can container handle this stiuation, even if we dont defined foreign key constraints at database level ? > > Is this something that developer has to take care of ? > > > > > > > > -- --Original Message-- -- > > From: Guy Katz [mailto:gkatz@(protected)] > > Sent: Sun 10/31/2004 7:54 AM > > To: J2EE-INTEREST@(protected) > > Cc: > > Subject: Re: EJB CMP 2.0 and Referential Integrity. > > > > > > > > if you use CMR > > referential intergrity is a built in part of the game. > > depending on the nature of your CMR definition (multiplicity etc..) > > the container will take care of it as long as you call your CMR methods. > > > > > > -- --Original Message-- -- > > From: A mailing list for Java(tm) 2 Platform, Enterprise Edition > > [mailto:J2EE-INTEREST@(protected)]On Behalf Of Naik, Vikram ( eBiz > > Mumbai ) > > Sent: Saturday, October 30, 2004 7:47 PM > > To: J2EE-INTEREST@(protected) > > Subject: EJB CMP 2.0 and Referential Integrity. > > > > > > Hello, > > > > What are the different ways to have referential integrity for your data, > > when the persistence is done using EJB CMP 2.0 ? > > > > We are using database foreign key constraints along with CMR to achieve the > > same ? > > > > Would appreciate all your thoughts on the above. > > > > Regards, > > Vikram. > > > > ================================================================== ========= > > To unsubscribe, send email to listserv@(protected) and include in the body > > of the message "signoff J2EE-INTEREST". For general help, send email to > > listserv@(protected) and include in the body of the message "help ". > > =========================================================================== To unsubscribe, send email to listserv@(protected) and include in the body of the message "signoff J2EE-INTEREST". For general help, send email to listserv@(protected) and include in the body of the message "help".
|
|