Hi there, more to this issue! Yes this is not possible with JBoss. I found out a few weeks a go and it took me just too long to get behind this. It should be possible in JBoss to defer the INSERT until ejbPostCreate which it can't do right now. There's a patch (request Id 612033 (CMR:foreign key as part of primary key)) on sourceforge which claims to fix a problem which has to do with this (a field that his both CMR and CMR). Maybe this help anybody. I had an exchange with JBoss developers and they thought this issue could be fixed by version 3.2 which should be out in January 03. Let's see, till then disabling the not null contraint or trying the deferred option in Oracle seems to be the only option.
BTW, a while ago I posted a report on this issue in this mailing list :) Cheers, Bernie -----Ursprüngliche Nachricht----- Von: Gavin Hughes [mailto:[EMAIL PROTECTED]] Gesendet: Montag, 18. November 2002 00:05 An: [EMAIL PROTECTED] Betreff: RE: [Middlegen-user] CMR in ejbPostCreate and NOT NULL foreign keys This is a JBoss problem, so I don't think there is anything you can do about it in Middlegen. JBoss does an INSERT after ejbCreate - as you are supposed to set CMR's in ejbPostCreate this results in an error as the FK field(s) are null at this point. You could try to work around this by declaring the foreign key(s) as CMP fields as well as CMR fields then setting the fk in ejbCreate - except that JBoss doesn't allow fields to be defined as CMP and CMR. There has been plenty of discussion on the topic on the JBoss mailing lists - at this point the usual recommendation is "don't define your foreign keys as NOT NULL". You can still keep your foreign key definitions - just define the constraints as deferrable, so they aren't checked until the "commit" (instead of happening after the insert in ejbCreate). For example (this works on Oracle) : ALTER TABLE LOCATION ADD CONSTRAINT FK_LOCATION_COUNTRY_ID FOREIGN KEY (country_id) REFERENCES COUNTRY (id) INITIALLY DEFERRED DEFERRABLE; The following post suggests there is a patch for JBoss that fixes the problem - but according to the details for this patch on sourceforge it doesn't actually work :-( http://www.mail-archive.com/jboss-user@lists.sourceforge.net/msg23045.html https://sourceforge.net/tracker/?func=detail&atid=376687&aid=630707&group_id =22866 Cheers, Gavin. -----Original Message----- From: Mustafa Radi [mailto:[EMAIL PROTECTED]] Sent: Sunday, 17 November 2002 6:48 PM To: Russell Black Cc: Eivind Waaler; [EMAIL PROTECTED] Subject: Re: [Middlegen-user] CMR in ejbPostCreate and NOT NULL foreign keys yes - I think you are right, I had the same problems and had to remove the NOT NULL statements in the database with jboss. Since jboss doesn't support the fkcmp="true" there is even no way to set this value at least to the right value when creating an EntityBean. The question is - where is the bug !!! Currently I don't believe its a middlegen problem ... cheers Russell Black wrote: No, I left fkcmp="true". Without that the struts won't compile. Anyway asyou said, that wouldn't help about the keys being set to null.It seems like this would be a problem intrinsic to all J2EE implementations,since:a) The J2EE container doesn't know the FK information until ejbPostCreate iscalled, andb) the INSERT statement happens before ejbPostCreate, therefore it *has* toinsert NULL for the foreign keys, violating the NOT NULL constraint socommon on foreign keys.Since Sun obviously thought this issue out, there is probably an error in mylogic above. Can anyone see it? Is anyone else having this problem?Thanks,Russell----- Original Message -----From: "Eivind Waaler" <[EMAIL PROTECTED]>To: "Russell Black" <russell.black @iarchives.com>Cc: <[EMAIL PROTECTED]>Sent: Saturday, November 16, 2002 8:21 AMSubject: Re: [Middlegen-user] CMR in ejbPostCreate and NOT NULL foreign keys Hmm, according to the SQL you're printing out there the two foreign keysare being set twice in the same statement. Are you using thefkcmp="false" attribute in your cmp20 plugin? Read the documentation aboutthis attribute here:http://boss.bekk.no/boss/middlegen/plugins/cmp20.html#fkcmpI guess that wouldn't help about the keys being set to null, weird wehaven't seen this error before though. I'll look into it on my examplerunning on weblogic..Regards.eivindOn Fri, 15 Nov 2002, Russell Black wrote: I know the spec says that CMR fields should be set in the post-create method, but it causes a problem when your table has a NOT NULL constraint onthe foreign key (CMR) column. Incidentally the airlines example suffersfrom this problem. I believe the issue is this: consider the followingtable: CREATE TABLE "reservations"( "reservation_id" INT NOT NULL, "person_id_fk" INT NOT NULL, "flight_id_fk" INT NOT NULL, "comment" VARCHAR, PRIMARY KEY ("reservation_id","person_id_fk","flight_id_fk"), FOREIGN KEY ("person_id_fk") REFERENCES "persons"("person_id"), FOREIGN KEY ("flight_id_fk") REFERENCES "flights"("flight_id"));ejbCreate is called, and it sets the CMP fields ONLY, and it tries to do the following SQL (copied from my JBOSS console) INSERT INTO reservation (reservation_id, person_id_fk, flight_id_fk, comment, flight_id_fk, person_id_fk) VALUES (5, NULL, NULL, 'A comment',NULL, NULL) Which fails because the foreign keys can't be null. The foreign keys aren't going to be set until the ejbPostCreate which happens AFTER theINSERT, so it never gets that far because the INSERT fails. Does this imply that foreign keys can't have NOT NULL values when using CMR? This seems bad, because the NOT NULL constraint is there for a reason. -------------------------------------------------------This sf.net email is sponsored by: To learn the basics of securing your web site with SSL, click here to get a FREE TRIAL of a Thawte Server Certificate: http://www.gothawte.com/rd524.html__________________________________________ _____middlegen-user mailing [EMAIL PROTECTED]https://lists.sourceforge.net/lists/ listinfo/middlegen-user This e-mail and any attachment is for authorised use by the intended recipient(s) only. It may contain proprietary material, confidential information and/or be subject to legal privilege. It should not be copied, disclosed to, retained or used by, any other party. If you are not an intended recipient then please promptly delete this e-mail and any attachment and all copies and inform the sender. Thank you. ------------------------------------------------------- This sf.net email is sponsored by: To learn the basics of securing your web site with SSL, click here to get a FREE TRIAL of a Thawte Server Certificate: http://www.gothawte.com/rd524.html _______________________________________________ middlegen-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/middlegen-user