Java Persistence Annotations (JPA)

IBM Industry Solutions Workbench generates default annotations whenever entities are created or edited. In Java domain services based on Java Stack 2.0 and with RDBMS enabled, it is possible to flexibly add custom annotations and costumize data persistence, e.g. by adding additional attributes to fields, tables, and columns. Additionally, you can override other JPA behavior by selecting different primary keys and define composite primary keys.

Custom JPA can be directly added to root entities, as well as to property associations of root entities. These are fully optional settings.

You can find more information on JPA in the official JPA documentation.

Root entity annotations

When creating or editing a root entity, you can create custom JPA table settings for the entity directly in the Designer:

  • Name, catalog and schema
  • Unique constraints
  • Indexes

Apart from these settings, you can add arbitrary annotations to the entity. These annotations should be fully qualified.

After creation, these settings are editable at any time under Edit entity details or Edit JPA table settings in the entity overview. You can also display which entities have custom JPA annotations in the Entities overview table of the namespace.

Note:

An index for a primary key (default and custom) will be created automatically.

Property association annotations

When adding a property to a root entity, you can create corresponding custom annotations directly in the Designer, defining columns and their properties as well as the collection table. Depending on the type of the associated property, different options are offered.

For properties, you have the following customization options:

  • Columns: name, length (if string-based), precision and scale (if numeric), uniqueness, nullability, insertability, updatability
  • Collection table: name, catalog, schema, unique constraints, indexes
  • Join columns: join columns

Apart from these settings, you can add arbitrary annotations to the property association. These annotations should be fully qualified.

After association, these settings are editable at any time under Edit property association of each property in the Associated properties at this level table in the entity overview. You can also display which properties are associated using custom annotations, or are used as a (composite) primary key in the Associated properties at this level table.

Note:

The type of the property association determines which JPA options are available.

Primary key

IBM Industry Solutions Workbench automatically generates a primary key for the entity. You can, however, also select one property of the type text, decimal, or integer as a custom primary key.

Note:

You can only mark one property as the (composite) primary key at the same time.

For the primary key, you have the following customization options:

  • Generation strategy: GenerationType.SEQUENCE, GenerationType.IDENTITY, GenerationType.TABLE, GenerationType.AUTO, GenerationType.UUID
  • Generator

For more information on the generated value, see here.

Composite key

You can also define a composite key for an entity.

  1. Create a simple entity. Root entities and external entities cannot be used.
  2. Associate the properties that should be part of the composite key to this entity.
  3. Associate the entity as a linked entity to the root entity you want to add the composite key to.
  4. Set the Composite key setting to true.

The properties of the entity are automatically added to the composite key.

Attention:

The composite key entity must not be used by any other entity as a non-primary key and must not have parents or children.

Note:

You can only mark one property/linked entity as the (composite) primary key at the same time.