This patch addresses issues with fields that exist as
both CMP fields and as part of a CMR field,
particularly when the field is not null.
There are two different issues addressed by these
changes. First, there are duplicate column names in
the insert and create table sql commands that jboss
generates. Second, jboss attempts to insert NULL values
for these fields, even when they are part of the
primary key.
The first issue is dealt with by building a list of
unique fields to use for the create table and insert
statements. This list of fields contains all the CMP
fields followed by the CMR fields that are not in the
CMP field list.
The second issue is taken care of by the insertion of
code to populate the bean instance values for the
duplicated CMR fields before the sql insert parameters
are bound. This way, when the parameter binding code
executes, the correct values are pulled from the bean
instance as if they had been set in ejbCreate. This is
accomplished by invoking the "get" method on the local
interface argument passed into ejbCreate. The way it
works is by querying the duplicated CMR field's related
field and extracting it's field name and it's local
interface name. Then, the arguments to ejbCreate are
inspected for a matching local interface name and a
matching get method for the field name. When it finds
a match, the get method is invoked and the return value
is assigned to the bean instance. For this change to
work properly, the local interfaces for the related
fields of the duplicated CMR fields must be passed in
as arguments to ejbCreate. Also, since the get method
is invoked and the bean instance value is set after the
ejbCreate call, any code in ejbCreate that sets the
field's bean instance value will be overridden.
This is the sequence of events.
1) ejbCreate is called normally and returns.
2) the patch code is called to populate duplicated CMR
field instance values
3) the primary key is extracted from the bean and
stored in the container context
4) the sql insert statement is prepared and executed.
5) ejbPostCreate is called.
unified diff