The Entity tab enables setting entity properties and managing its attributes.
- Class Name is the name of the new entity class.
- Package Name is a Java package.
- Name is the name of the new entity in the
prefix$Name
form, where prefix
is the project namespace, and Name
is the entity class name. This name is used for the entity in metadata and in JPQL queries.
- Table is the name of the corresponding database table in the
PREFIX_NAME
format, where PREFIX
is the project namespace.
Entity and table names are generated automatically as you specify the class name, but can be changed.
- Parent class should be either one of the base entity classes, or another entity. Two base entity classes are recommended for use in most cases:
- StandardEntity - the base class of persistent entities that implements versioning, soft deletion and changes history interfaces.
- BaseUuidEntity - the base class of persistent entities which declares commonly used methods for processing entity instance creation information. As you select this entity type, the Updatable, Soft Delete and Versioned checkboxes become available, enabling to select the interfaces to be implemented.
If you inherit this entity from another entity and if the parent class defines the JOINED
inheritance strategy, the following fields become available:
- Discriminator - the value to be used for a discriminator column defined in the parent table. This value must be unique for the given hierarchy.
- Primary key join column - column in this table to be used as a primary key which is also the foreign key referencing the parent table.
- Referenced primary key column - the primary key column of the parent table.
- Replace Parent - specifies that the entity should be used everywhere instead of the parent class.
- Inheritance strategy - inheritance type starting from the current entity and down to subclasses. The default strategy is
SINGLE_TABLE
. This field should only be used if you want to implement the hierarchy both on the classes and database level. In other scenarios, consider using mapped superclasses, which enable grouping common attributes in base classes but storing them in separate tables of the subclasses.
The following fields are available if you choose SINGLE_TABLE
or JOINED
inheritance strategy:
- Discriminator column name - the column used to discern records of different subtypes. Inherited entities define particular discriminator value in their Discriminator field.
- Discriminator type - type of the discriminator column.
Attributes table displays the entity attributes. Click New and specify the following properties to add a new attribute:
- Name - the name of the new attribute. Use lowerCamelCase, e.g.
invoiceNumber
. You should also specify the attribute's localized name to be used in UI by default. To do this, click the button next to the field and specify the attribute name in the languages available in your project.
- Attribute type - the type of the attribute. The platform supports the following attribute types:
- DATATYPE - an attribute of one of the basic types supported by the Datatype interface. The data type can be selected in the Type field below. For
String
attributes, the maximum length should be specified in the Length field, otherwise the corresponding database column will be created with unlimited length type, e.g. LONGVARCHAR
. For BigDecimal
attributes, precision and scale must be specified in the respective fields.
- ENUM - an enumeration. Before adding an enum attribute, you must create the corresponding enumeration using the Studio's Enumerations section.
- ASSOCIATION - a reference attribute creating a simple relationship between the current entity and another entity.
- COMPOSITION - a reference attribute creating a relationship with an entity that has no values independent of the current entity. In other words, the current entity owns the related entity.
For both types of reference attributes (ASSOCIATION and COMPOSITION) the linked entity must be selected in the Type field. You must also specify relationship cardinality, deletion policy and collection type if the cardinality is TO_MANY
.
Collection attributes require corresponding inverse attributes in the referenced entities. These inverse attributes can be created by selecting an attribute in the table and clicking Create inverse attribute in the dropdown list of the Mapped by field. The attribute properties editor will open in a new window, enabling you to create a new attribute for mapping your collection attribute on the inverse side.
- EMBEDDED - an embeddable entity.
- Read only checkbox specifies that the attribute value cannot be modified.
- Mandatory checkbox specifies that the attribute is required and cannot be null.
- Column is the name of the corresponding database table column. This field is filled in automatically as you specify the attribute name.
Entity attributes can be edited later by selecting them in the list. Entity properties will appear in the right panel of the designer workspace.
Attributes can be moved up and down in the list using Up and Down buttons. This will change their location in the source code.