As Alex Lobansky has already said, you can't. But, here's what we do to
work around the problem.
1. Add cmp fields for all the non-null foreign keys.
2. In the ejbCreate, call "setNonNullFKCmpField( fkObj.getPrimaryKey())".
3. Remove any call to "setNonNullFKCMRField( fkObj)", as you've already
done the work.
4. Add ejbSelect methods to get the fkObj given its id. This is easy to do
if you're using XDoclet (but don't use 1.1.2, get the beta instead)
5. Rewrite getFKCMRField() funtion like so:
public FKObj getFKCMRField() {
Collection objs = ejbSelectFKObjs( getFKCMPField());
Iterator it = objs.iterator();
return (FKObj) it.next();
}
6. Rewrite setFKCMRField( FKObj fkObj ) {
setFKCMPField( fkObj.getPrimaryKey());
}
If you're relationship is bidirectional, you'll have to do something
similar on the other side as well.
Given a free choice, I'd just turn off the NOT-NULL DB constraint, but
politically, I couldn't do that, so we went through much pain.
I have been looking at ways of allowing a CMP and a CMR field to access
the same DB column, but so far I've only had partial success. You may be
able to get away with it on some DBs. But Oracle is not forgiving.
Ciao,
Jonathan O'Connor
Ph: +353 1 872 3305
Mob: +353 86 824 9736
Fax: +353 1 873 3612
"Michael Angelo Libio" <[EMAIL PROTECTED]>
Sent by: [EMAIL PROTECTED]
08.11.2002 10:14
Please respond to jboss-user
To: [EMAIL PROTECTED]
cc:
Subject: [JBoss-user] ejbCreate violating database 'NOT NULL'
constraints (foreign
keys)
How can I avoid violating NOT NULL constraints on foreign keys that are
mapped to cmr-fields?
I know that we're not suppose to set cmr fields during the ejbCreate
method
of an entity bean. However, it seems that the call to "insert into" is
executed before the cmr fields are set (ejbPostCreate). Is there a way
around this? I'd like to keep my database schema the way it is (with it's
relationship intact).
_________________________________________________________________
The new MSN 8: advanced junk mail protection and 2 months FREE*
http://join.msn.com/?page=features/junkmail
-------------------------------------------------------
This sf.net email is sponsored by: See the NEW Palm
Tungsten T handheld. Power & Color in a compact size!
http://ads.sourceforge.net/cgi-bin/redirect.pl?palm0001en
_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-user
-------------------------------------------------------
This sf.net email is sponsored by: See the NEW Palm
Tungsten T handheld. Power & Color in a compact size!
http://ads.sourceforge.net/cgi-bin/redirect.pl?palm0001en
_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-user