Auto-generating Primary Keys
Written by Joseph Ottinger
Sequences are database-specific mechanisms to generate counters, but that's not very useful for EJBs, since they don't have to map to databases. That leaves EJB authors with the problem of generating unique identifiers for beans.
Orion comes with a deployable EJB, in a file called "counter.jar". To use it, follow these steps:
<module><ejb>counter.jar</ejb></module>
<ejb-ref>
<ejb-ref-name>ejb/Counter</ejb-ref-name>
<ejb-ref-type>Entity</ejb-ref-type>
<home>com.evermind.ejb.CounterHome</home>
<remote>com.evermind.ejb.Counter</remote>
</ejb-ref>
com.evermind.ejb.CounterUtils.getNextID("java:comp/env/ejb/Counter", "mybeanname")
Note that the same counter deployment can be used for any unique counter; all you would do is specify a different "bean name" (actually just a unique identifier of some kind) in the getNextID() function call.
Copyright © 2007 IronFlare AB