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".