Composite key support

Does CUBA support a composite key of Entity? I found some forum posts but didn’t find a concrete example. I have an Entity called TaxYear where I need the fields Country and year should be unique i.e. Country+year.

Let me bring the example.
We need entity “Document” with the following fields: code, name, description, state.
We want code and name to be the PK of Document.

  1. Using Studio create a new entity with the name “DocumentPK”. Select Entity type = Persistent embedded.
  2. Add a pair of String fields: code and name.
  3. Create another entity “Document”. Select Id type = Embedded. And DocumentPK.
  4. Add description and state to Document.
    The resulting entity has composite PK and looks as follows.
@Table(name = "MASTAR_DOCUMENT")
@Entity(name = "mastar$Document")
public class Document extends BaseGenericIdEntity<DocumentPK> {
    private static final long serialVersionUID = 5809666985606746267L;

    @Column(name = "DESCRIPTION")
    protected String description;

    @Column(name = "STATE")
    protected Integer state;

    protected DocumentPK id;

//Setters and Getters



1 Like