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.

Hi,
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.
    public://attachments/3fe5e2267dfd9ada4b714fdd4f17d211.jpg
  2. Add a pair of String fields: code and name.
  3. Create another entity “Document”. Select Id type = Embedded. And DocumentPK.
    public://attachments/6d58abc5b03f55f89df341aefbafc336.jpg
  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;

    @EmbeddedId
    protected DocumentPK id;

//Setters and Getters
..

3fe5e2267dfd9ada4b714fdd4f17d211

6d58abc5b03f55f89df341aefbafc336

1 Like