This problem can be fixed easily, if you are willing to change the JBoss source code. See my message below for more details.

Dain, I'm not sure if you saw my post, but I'd appreciate your opinion as to whether this code is safe or not.

Ciao,
Jonathan O'Connor
Ph: +353 1 872 3305
Mob: +353 86 824 9736
Fax: +353 1 873 3612

----- Forwarded by Jonathan O'Connor/X-WORLD/DE on 14.06.2002 09:58 -----
Jonathan O'Connor

13.06.2002 12:19


        To:        [EMAIL PROTECTED]
        cc:        
        Subject:        Re: CMP Bug: Bad SQL for FK fieldLink


We fixed our problems by hacking the JBoss source! Thank God for open source.

We changed the getInsertFields() in JDBCCreateEntityCommand to call entity.getCmpFields() instead of entity.getFields(). The entity.getFields() gives you a list of CMP and CMR fields, and of course, if a CMP and CMR field map to same DB column, then we get our bad INSERT statement.

Now, our INSERT command only contains the CMP fields, and none of the nulled CMR fields. Our old workaround works again. We set the FK field using the CMP setter in ejbCreate() and then we have to set it again usin the CMR setter at ejbPostCreate(). Yeah, I know we could just make the column nullable, but don't ask!

Dain, is this a legitimate fix? We reckon its safe as CMR fields should only be set in ejbPostCreate(). Also, the INSERT statement should be smaller.

I was also having a look at the source to see if we could move the record insertion to after the ejbPostCreate. In CMPPersistenceManager, the CreateEntity() method calls store.createEntity(...). Would it be possible to ask the entity for its primary key (This is actually done in the JDBCCreateEntityCommand.execute() method). Use the key to patch up the cache, and then move the call to store.createEntity() to postCreateEntity() method? I'm sure its not so simple, but you never know!

Finally, I suppose this thread should be moved to the developer list.
Ciao,
Jonathan O'Connor
Ph: +353 1 872 3305
Mob: +353 86 824 9736
Fax: +353 1 873 3612



Guys,
Just to add some information for who ever's fixing the nullable foreign key field problem.
In JBoss 3.0.0 alpha, we had a work around. We declared both a CMP and CMR field for the same DB column (the FK field).
Then in ejbCreate() we called setCmpFKField( obj.getId() ), and in ejbPostCreate() we called setCmrFKObj( obj )

This worked fine, although we did an INSERT and then an unnecessary UPDATE.

When we try this solution in JBoss 3.0.0 Final, the system generates an INSERT statement with two references to the FK Column. Oracle (in our case) rejects this as bad SQL.

Question 1: Is it according to the EJB 2 spec to have a CMR and CMP field for the same DB column?
Question 2: Will the fix for non-null foreign key fields be made available as a patch

Reply via email to