If I create() single Entity bean, then update its properties, and when
SessionBean's method exits, transaction is commited. The record is
inserted into the table with all fields correctly populated.
But if I perform a loop like
for (int i=0; i<100; i++) {
MyEntity entity = MyEntityHome.create();
entity.setProperty1 ("a");
entity.setProperty2 ("b");
}
and 3 entities will be created as result, when transaction is
commited, I will get one record correctly populated with data of the
100th entity bean, and the rest 99 records will have null values in
all fields.
I understand, that in CMP2, Integer MyEntityBean.ejbCreate() must
return null.
Since I rely on container to manage primary keys and take care of
referential integrity, I do not set primary key in this method, and
neither do I set other properties on the entity bean. Now, if I call
create(), I will get exception because container will try to insert
into table (pk, field, field2) values (null,null,null).
So I tried to set all values to (new Integer(0), "", ""), but then I
get effect described above - 1st record is populated with data of last
record, and other N-1 records are nulls (except for primary key, of
course).
What's the proper way to
o initialize entity beans in ejbCreate() for CMP2 ?
o make container set primary key back to EJB after record had been
inserted and Autonumber has been allocated for that record ?
1:
<table-properties>
<table-name>TstTbl</table-name>
<column-properties>
<column-name>id</column-name>
<property>
<prop-name>ignoreOnInsert</prop-name>
<prop-type>java.lang.Boolean</prop-type>
<prop-value>true</prop-value>
</property>
</column-properties>
...
2:
...
</property>
<property>
<prop-name>getPrimaryKeyAfterInsertSql</prop-name>
<prop-type>String</prop-type>
<prop-value>select DBInfo('sqlca.sqlerrd1') from
systables where tabname='TstTbl'</prop-value>
</property>
</table-properties>
P.S you can configure this from within the ide by setting the table &
column properties, thus avoiding having to modify the DD manually
Hope this helps.
-Marcus.
maxim...@bigfoot.com (msenin) wrote in message news:<d1004ecb.02081...@posting.google.com>...