Title: Message
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 as
you 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 is
called, and
b) the INSERT statement happens before ejbPostCreate, therefore it *has* to
insert NULL for the foreign keys, violating the NOT NULL constraint so
common on foreign keys.

Since Sun obviously thought this issue out, there is probably an error in my
logic 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 AM
Subject: Re: [Middlegen-user] CMR in ejbPostCreate and NOT NULL foreign keys


Hmm, according to the SQL you're printing out there the two foreign keys
are being set twice in the same statement. Are you using the
fkcmp="false" attribute in your cmp20 plugin? Read the documentation about
this attribute here:

http://boss.bekk.no/boss/middlegen/plugins/cmp20.html#fkcmp

I guess that wouldn't help about the keys being set to null, weird we
haven't seen this error before though. I'll look into it on my example
running on weblogic..

Regards
.eivind

On 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 on
the foreign key (CMR) column. Incidentally the airlines example suffers
from this problem. I believe the issue is this: consider the following
table:
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 the
INSERT, 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 list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/middlegen-user




Reply via email to