This is what we do(we use Oracle).
In each <entity> entry in ejb.jar.xml, we declare the following env entries:
<env-entry>
<description>
</description>
<env-entry-name>connectionPoolName</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>oraclePool</env-entry-value>
</env-entry>
<env-entry>
<description>
</description>
<env-entry-name>sequenceName</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>SEQ_BILL_ID</env-entry-value>
</env-entry>
And the following base class for each Entity
class EntityBase implements EntityBean
{
protected String getSequenceName() throws NamingException
{
InitialContext iCtxt = getInitialContext();
return (String)iCtxt.lookup("java:comp/env/sequenceName");
}
protected String getConnectionPoolName() throws NamingException
{
InitialContext iCtxt = getInitialContext();
return (String)iCtxt.lookup("java:comp/env/connectionPoolName");
}
protected long generateId()
{
long id = 0;
//...sum sugar...
InitialContext iCtxt = getInitialContext();
String seqName = getSequenceName();
String poolName = getConnectionPoolName();
ResultSet results = SQLUtils.executeSQLQuery(poolName, "select "
+ seqName + ".nextval from DUAL");
//.....extract id....
return id;
}
}
Hope the above code fragments help you out.
Bill
> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED]]On Behalf Of Hunter
> Hillegas
> Sent: Friday, August 03, 2001 12:53 AM
> To: JBoss 2
> Subject: [JBoss-user] Okay... Sequences and CMP Again...
>
>
> I read through the archives and I still couldn't find even a partial
> consensus on the best method for this...
>
> I'm using PostgreSQL and CMP and trying to figure out the best way to fill
> my integer primary key field.
>
> My database has sequences... Should I use JDBC to get a sequence id in the
> ejbCreate() method? Does that spoil the whole point of CMP?
>
> Other ideas?
>
> Hunter
>
>
> _______________________________________________
> JBoss-user mailing list
> [EMAIL PROTECTED]
> http://lists.sourceforge.net/lists/listinfo/jboss-user
>
_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-user