16.9.4. Configure EJB 2.x Container-Managed Persistence

The EJB 2.x Container Managed Persistence (CMP) subsystem can be configured to specify any number of key generators. Key generators are used to generate unique keys to identify each entity persisted by the CMP service.
Two types of key generator can be defined: UUID-based and HiLo key generators.
UUID-based key generators
A UUID-based key generator creates keys using Universally Unique Identifiers. UUID key generators only need to have a unique name, they have no other configuration.
UUID-based key generators can be added using the CLI using the following command syntax.
 /subsystem=cmp/uuid-keygenerator=UNIQUE_NAME:add 

Example 16.16. Add UUID Key Generator

To add a UUID-based key generator with the name of uuid_identities, use this CLI command:
/subsystem=cmp/uuid-keygenerator=uuid_identities:add
The XML configuration created by this command is:
<subsystem xmlns="urn:jboss:domain:cmp:1.0"> 
   <key-generators>
      <uuid name="uuid_identities" />
   </key-generators>
</subsystem>
HiLo Key Generators
HiLo key generators use a database to create and store entity identity keys. HiLo Key generators must have unique names and are configured with properties that specify the datasource used to stored the data as well as the names of the table and columns that store the keys.
HiLo key generators can be added using the CLI using the following command syntax:
 /subsystem=cmp/hilo-keygenerator=UNIQUE_NAME/:add(property=value, property=value, ...) 

Example 16.17. Add a HiLo Key Generator

/subsystem=cmp/hilo-keygenerator=DB_KEYS/:add(create-table=false,data-source=java:jboss/datasources/ExampleDS,drop-table=false,id-column=cmp_key_ids,select-hi-ddl=select max(cmp_key_ids) from cmp_key_seq,sequence-column=cmp_key_seq,table-name=cmp-keys))
The XML configuration created by this command is:
<subsystem xmlns="urn:jboss:domain:cmp:1.0"> 
   <key-generators>
      <hilo name="DB_KEYS">
         <create-table>false</create-table>
         <data-source>java:jboss/datasources/ExampleDS</data-source>
         <drop-table>false</drop-table>
         <id-column>cmp_key_ids</id-column>
         <select-hi-ddl>select max(cmp_key_ids) from cmp_key_seq</select-hi-ddl>
         <sequence-column>cmp_key_seq</sequence-column>
         <table-name>cmp-keys</table-name>
      </hilo>
   </key-generators>
</subsystem>