3 Replies Latest reply on Aug 6, 2002 7:03 PM by dsundstrom

    set not null foreign key in ejbCreate

    nicholasgreg

      In CMP2.0, I'm not allowed to call the setters in my entity beans, which JBoss correctly stops me from doing so.

      However, a relationship does not allow NULL value in the database table. Say CustomerEJB has one AddressEJB. The customer table has an address_fk column which is NOT NULL.

      By calling CustomerEJB.create(), the generated SQL violates the database constraint, obviously. I've spent a long time trying to get pass this, but there is no way I can call the setAddress() method inside say, ejbCreate(Address) and get the container to insert with the correct address_fk from the object.

      The only thing I know is WebLogic 7.0 seems to solve this by having a 'delay-insert-statement', which allows the server to send the insert after ejbPostCreate(). This means under CMP2.0 and JBoss 3.0, I can't have a proper 1 to 1 relationship when the fk is in the source object, instead a 1 to 0..1 appears to be the only option!

      Is there any expert out there who can share their solutions? (dropping 'not null', or WLS 7.0 are all I can think of)

      thanks