Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> EJB & Primary Keys
One of our developers is writing a container managed EJB (entity beans) to insert records into a table. Let's say the table name is
emps(emp_id NUMBER(10),
emp_name VARCHAR2(10))
In the entity bean, they intend to insert just
the employee name, and have the primary key
generated through a before insert trigger
automatically.
Now the question becomes how does the entity
bean know about the primary key created
through the trigger.
Right now they have a trigger and pass a 0 for
emp_id and triggers generates it's own sequence
number before insert.
The second insert fails with a duplicate primary key.
Looks like the container caches sequence numbers.
Programmers are reluctant to clutter the code with JDBC calls to get the sequence number for primary key.
Did anyone run into this situation?
How does everyone else generate a primary key using
entity beans?
Your input is greatly appreciated.
Thank you,
Kittu.
Received on Tue Aug 01 2000 - 00:00:00 CDT