The SequenceGenerator module is an EJB-only module and provides a standard way to generate ID values for CMP entity beans, a feature left out from the EJB specification.
Note that the SequenceGenerator EJBs need an EJB 2.0 or higher compliant container.
SequenceGenerator is an EJB module that provides a very efficient unique ID generator. The primary use of this is as auto-incrementing primary-keys in entity beans, using a high/low algorithm. The following example code shows how one can a new ID in the sequence named "testSequence":
SequenceGeneratorHome sgh = (SequenceGeneratorHome)EJBUtils.lookup("ejb/os.SequenceGenerator"); SequenceGenerator sg = sgh.create(); long nextId = sg.getCount("testSequence");
We recommend that if you are going to access the SeqenceGenerator from an EJB or a JSP/Servlet, you place the following ejb-ref in your deployment descriptor. You'll also want to map this ejb-ref to the jndi- name os.SequenceGenerator using a vendor-specific deployment descriptor:
<ejb-ref> <ejb-ref-name>ejb/os.SequenceGenerator</ejb-ref-name> <ejb-ref-type>Session</ejb-ref-type> <home>com.opensymphony.module.sequence.SequenceGeneratorHome</home> <remote>com.opensymphony.module.sequence.SequenceGenerator</remote> <ejb-link>os.SequenceGenerator</ejb-link> </ejb-ref>