21.9. Configuring EJB 2.x Entity Beans

21.9.1. EJB Entity Beans

EJB Entity Beans are a type of enterprise bean from version 2.x of the EJB specification that represented persistent data that was maintained in a database. Entity beans have been superseded by JPA entities and officially listed for removal (pruning) from future versions of the specification. Red Hat does not recommend the use of Entity Beans except for backwards compatibility.
Support for Entity Beans is disabled by default in JBoss EAP 6.


JBoss EAP 6.x supports EJB 2.0 and above, with the exception that EJB 2.0 deployment descriptors only work in JBoss EAP 6.4 and above.

21.9.2. Container-Managed Persistence

Container-Managed Persistence (CMP) is an application server provided service that provides data persistence for Entity beans.

21.9.3. Enable EJB 2.x Container-Managed Persistence

Container-Managed Persistence (CMP) is handled by the org.jboss.as.cmp extension. CMP is enabled by default in the managed domain and standalone server full configurations, e.g. standalone-full.xml.
To enable CMP in a different configuration, add the org.jboss.as.cmp module to the list of enabled extensions in the server configuration file.
        <extension module="org.jboss.as.cmp"/>
Once the extension has been added, you must also add the following element in the profile's XML configuration file under the <profile> element.
<subsystem xmlns="urn:jboss:domain:cmp:1.1"/>
To disable CMP in a server configuration, remove the extension entry for the org.jboss.as.cmp module.

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

Example 21.17. Add UUID Key Generator

To add a UUID-based key generator with the name of uuid_identities, use this CLI command:
The XML configuration created by this command is:
<subsystem xmlns="urn:jboss:domain:cmp:1.0"> 
      <uuid name="uuid_identities" />
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 store 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 21.18. Add a HiLo Key Generator

/subsystem=cmp/hilo-keygenerator=HiLoKeyGeneratorFactory:add(create-table=true,create-table-ddl="create table HILOSEQUENCES (SEQUENCENAME varchar(50) not null, HIGHVALUES integer not null, constraint hilo_pk primary key (SEQUENCENAME))",data-source=java:jboss/datasources/ExampleDS, id-column=HIGHVALUES,sequence-column=SEQUENCENAME,table-name=HILOSEQUENCES,sequence-name=general,block-size=10)
The XML configuration created by this command is:
<subsystem xmlns="urn:jboss:domain:cmp:1.1">
         <hilo name="HiLoKeyGeneratorFactory">
             <create-table-ddl>create table HILOSEQUENCES (SEQUENCENAME varchar(50) not null, HIGHVALUES integer not null, constraint hilo_pk primary key (SEQUENCENAME))</create-table-ddl>


The block-size must be set to a value !=0, otherwise the generated PKey will not incremented and therefore the creation of entities fail with a DuplicateKeyException.


The select-hi-ddl must be set as 'FOR UPDATE' in case of cluster to ensure the consistency. All databases do not support the locking feature.

21.9.5. CMP Subsystem Properties for HiLo Key Generators

Table 21.1. CMP Subsystem Properties for HiLo Key Generators

Property Data type Description
block-size long
The block size.
create-table boolean
If set to TRUE, a table called table-name will be created using the contents of create-table-ddl if that table is not found.
create-table-ddl string
The DDL commands used to create the table specified in table-name if the table is not found and create-table is set to TRUE.
data-source token
The data source used to connect to the database.
drop-table boolean
To determine whether to drop the tables.
id-column token
The ID column name.
select-hi-ddl string The SQL command which will return the largest key currently stored.
sequence-column token
The sequence column name.
sequence-name token
The name of the sequence.
table-name token
The name of the table used to store the key information.