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.JOINED
inheritance strategy is defined for theCard
class, thusEBook
will be stored in a separate table, and its primary key will be an external key that references theCard
primary 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 theCard
base 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
0
for base type instances. Therefore, it is sufficient to assign any value other than0
for theEBook
type. -
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
Card
entity is selected. In this case, it is ID.
Next, let us create an entity attribute containing a link to the book publication.
Click Create attribute window:
under the list of attributes and specify the following properties in the-
Name -
publication
-
Attribute type -
ASSOCIATION
-
Type -
BookPublication [library$BookPublication]
-
Mandatory -
on
. This means the attribute is required. -
Cardinality -
MANY_TO_ONE
. This means that severalEBook
instances can be created for oneBookPublication
instance. -
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 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.
in theChoose
-> to stop the application server. The -> menu item, which should be used, will become available in a few seconds.