Let us create an EBook entity class that will represent the electronic version of the book publication. The Ebook class must be derived from the Card (process card) in order to manage the EBook state in accordance with the required business process.
Go to the Entities tab on the Studio navigation panel, select the com.sample.library.entity package and click . Specify the following entity properties:
-
Class name -
EBook -
Table -
LIBRARY_EBOOK -
Parent class -
Card [wf$Card]. TheInheritanceType.JOINEDinheritance strategy is defined for theCardclass, thusEBookwill be stored in a separate table, and its primary key will be an external key that references theCardprimary key. -
Discriminator -
10. A discriminator is the value of a base type field that will be set in the database for all instances of this specific type. In this case, the following annotations have been defined for theCardbase class:@DiscriminatorColumn(name = "CARD_TYPE", discriminatorType = DiscriminatorType.INTEGER) @DiscriminatorValue("0")This means that the CARD_TYPE field must store an integer value, which will be equal to
0for base type instances. Therefore, it is sufficient to assign any value other than0for theEBooktype. -
In the Primary key join column field, the CARD_ID name for the primary key of the created entity is automatically generated.
-
In the Referenced primary key column field, the primary key for the WF_CARD table that stores the base
Cardentity is selected. In this case, it is ID.
Next, let us create an entity attribute containing a link to the book publication.
Click under the list of attributes and specify the following properties in the Create attribute window:
-
Name -
publication -
Attribute type -
ASSOCIATION -
Type -
BookPublication [library$BookPublication] -
Mandatory -
on. This means the attribute is required. -
Cardinality -
MANY_TO_ONE. This means that severalEBookinstances can be created for oneBookPublicationinstance. -
The Column field will contain the appropriate column name - PUBLICATION_ID.
Save the changes. As a result, the following entity class will be created:
package com.sample.library.entity;
import javax.persistence.*;
import com.haulmont.workflow.core.entity.Card;
@PrimaryKeyJoinColumn(name = "CARD_ID", referencedColumnName = "ID")
@DiscriminatorValue("10")
@Table(name = "LIBRARY_EBOOK")
@Entity(name = "library$EBook")
public class EBook extends Card {
private static final long serialVersionUID = -7326357893869004530L;
@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "PUBLICATION_ID")
protected BookPublication publication;
public void setPublication(BookPublication publication) {
this.publication = publication;
}
public BookPublication getPublication() {
return publication;
}
}After the entity class is created, the Studio will report that the data model has been changed and now differs from the current database schema. It is necessary to generate the scripts and to start the database creation or update process.
Click in the Entites section of the navigation panel. The Studio will generate the database update and initialization scripts, which include the creation of the LIBRARY_EBOOK table and its foreign keys. Since our database contains no data and can be easily recreated, you can safely delete the scripts in the Update scripts tab. After that, save the changes.
Choose -> to stop the application server. The -> menu item, which should be used, will become available in a few seconds.


