Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> EJB & Primary Keys

EJB & Primary Keys

From: Chakravarthy KM Nalamotu <kittu_at_uhunix1.its.hawaii.edu>
Date: 2000/08/01
Message-ID: <8m70fl$hah$1@news.hawaii.edu>#1/1

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

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US