Hi Neil,

> Where and how are the keys generated?

The answer to your question is really 2-layered.  On the database side, the
primary key generation is based on the db implementation.  For a SQL table
with a column declared as the PK, this sequence is generated and maintained
by the database.  And if you simply map a row in this table to an entity
bean, in most cases your EJB PK would be a wrapper (or custom class) to this
database PK.

However, if you require a more complex EJB PK, e.g. one that maps to more
than one column in your db table, then you would define a PK class that
holds references to these two values.  Hence you "generate" your PK from the
two values you decide to insert into your db table.

So technically, in either case, YOU are responsible for creating the PK
object from info you obtain either from the db or elsewhere (static counter,
GUID, Unique PK generating algorithm, etc..)

> But, what I dont know the PK ever gets set.

When you ejbCreate a new bean, you create the PK object in this method and
pass it out in the return; the server container the takes over and does the
"setting".  This implementation is vendor-specific, but in general the
container would

   1) create an EntityContext that refers to the pk
   2) create an EJBObject that's somehow affiliated to this EntityContext
   3) return the EJBObject to you (from EJBHome.create)

You now have a remote EJB reference from which you can retrieve the primary
key, as well as bean info.

Hope that helps a little!

Gene Chuang
Teach the world... Join Kiko!
http://www.kiko.com/profile/join.jsp?refcode=TAF-gchuang


-----Original Message-----
From: A mailing list for Enterprise JavaBeans development
To: [EMAIL PROTECTED]
Sent: 8/29/00 9:27 PM
Subject: Newbie question: How are keys generated?

Hello:

I am new to EJB and I am sure that it shows, but I have
a very simple question:  Where and how are the keys
generated?

I have read everythign I can find and all the docs and
books talk about the higher level stuff, but this question
still causes me to wonder.

For example, I am trying to model an Employee
that has a Name.

So, I created a database table:
   CREATE TABLE Employee (
        Employee_PK INTEGER NOT NULL,
        Name VARCHAR NOT NULL
    )

I think I understand how to write the EJB, do all the BMP
SQL code, etc., etc.

But, what I dont know is how the PK ever gets set.

Can anyone clear this up for me?

Thanks,
        Neil.

--
Neil Aggarwal, President & CEO
JAMM Consulting, Inc. (http://www.JAMMConsulting.com)
Custom Programming in Java, C, C++, perl, HTML, CGI

========================================================================
===
To unsubscribe, send email to [EMAIL PROTECTED] and include in the
body
of the message "signoff EJB-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to