Hi All...

I am working on an EJB project. Currently, I am planning to use the
JOnAS EJB server with PostgreSQL, but I don't think that is important.

When I designed my data tables, I had planned to use a sequence field for 
the primary key of each table. A sequence is called a few different things, 
depending upon the database in use. For example, MS SQL Server calls it an 
"identity field." Its just a field that is automatically assigned a unique 
value each time a record is inserted, so that each record has a guaranteed 
unique value in this field. A SQL app would insert a record and then do a 
select to read back the value assigned to that records sequence field.

Anyhow, I discovered that in my CMP entity beans ejbCreate method I must 
populate all the fields which are part of the primary key. When this method 
returns, the container creates an instance of the primary key object and 
then adds a record to the database. Thats all fine, but if I use a sequence 
field as the primary key it has no value until the record is created, at 
which point its too late for me to populate the primary key attribute in my 
class, since the ejbCreate method has already returned at this point. 
Therefor, it seems that this approach makes instansiating a primary key 
object problematic if it maps to a sequence field.

I had though about using the ejbPostCreate method to lookup the assigned 
value for the sequence field and produce a new primary key object, but I 
think its likely that the primary key object plays a part in the assignment 
of context to the entity bean after ejbCreate returns and before 
ejbPostCreate is called, so this might screw up that activity on some EJB 
implementations.

So, my question is, is it possible using only features outlined in the EJB 
1.1 spec to use a database sequence fields as a primary key?

I hope I made this clear. Its kind of late (early) here...

Thanks to all!

Jim



----
To unsubscribe, send email to [EMAIL PROTECTED] and
include in the body of the message "unsubscribe jonas-users".
For general help, send email to [EMAIL PROTECTED] and
include in the body of the message "help".

Reply via email to