I'm sorry for the ignorance, but for my enlighment, I would appreciate an answer to these questions:
1) What's this Sequence class? I couldn't find it in either java.sql nor javax.sql 2) Do all databases support a db-independent(portable) way of generating sequence numbers? TIA, Juan Pablo Lorandi Chief Software Architect Code Foundry Ltd. [EMAIL PROTECTED] Barberstown, Straffan, Co. Kildare, Ireland. Tel: +353-1-6012050 Fax: +353-1-6012051 Mobile: +353-86-2157900 www.codefoundry.com > -----Original Message----- > From: A mailing list for Enterprise JavaBeans development > [mailto:[EMAIL PROTECTED]] On Behalf Of Vincent Shek > Sent: Friday, June 21, 2002 6:55 PM > To: [EMAIL PROTECTED] > Subject: How to use sequence generator for primary key in CMP? > > > Hi all, > > What's the recommended way to use database sequence generator > for use to = generate primary key in CMP? > > I am using Weblogic and it has its own solution of using = > <automatic-key-generation> in the deployment descriptor but > obviously = it's not a portable solution. > > An obvious solution is to do something like this: > > public Integer ejbCreate(String username, String password) > throws=20 CreateException { > this.userId =3D getIdFromSequence(); > this.userName =3D username; > this.password =3D password; > return null;=20 > } > > private Integer getIdFromSequence() { > Connection con =3D null; > Integer newId =3D null; > Sequence seq =3D null; > try { > con =3D getConnection(); > seq =3D new Sequence(con, "DATABASE_SEQ"); > newId =3D new Integer(seq.nextValue()); > } catch (Exception e) { > e.printStackTrace(); > } finally { > try { > if (seq !=3D null) seq.close(); > if (con !=3D null) con.close(); > } catch (DataSetException dse) { > dse.printStackTrace(); > } catch (SQLException se) { > se.printStackTrace(); > } > } > return newId; > } > > But the above solution involves 2 trips to the database which > may or may = not become a performance bottleneck. > > Vincent > > ============================================================== > ============= > 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".
