Skip to content

REST API does not support entities with composite primary key #49

@haulmont-git

Description

@haulmont-git

Since id of such entities is passed as object it's not possible to call some methods where id is used in path fragment

DELETE /entities/{entityName}/{entityId}
GET /entities/{entityName}/{entityId}
PUT /entities/{entityName}/{entityId}

Solution:
Represent composite key identifier as JSON string and apply base64 URL encoding.

Model:

@Entity(name = "ref$CompositeKeyEntity")
@Table(name = "REF_COMPOSITE_KEY")
public class CompositeKeyEntity extends BaseGenericIdEntity<EntityKey> {

    private static final long serialVersionUID = -2538345720324624741L;

    @EmbeddedId
    private EntityKey id;

    @Column(name = "NAME")
    private String name;  
}

@Embeddable
@MetaClass(name = "ref$EntityKey")
public class EntityKey extends EmbeddableEntity {

    @Column(name = "TENANT")
    private Integer tenant;

    @Column(name = "ENTITY_ID")
    private Long entityId;
}

Encoding sample:

  • JSON: {tenant : 1, entityId: 1}
  • Base 64: e3RlbmFudCA6IDEsIGVudGl0eUlkOiAxfQ==
  • GET /entities/ref$CompositeKeyEntity/e3RlbmFudCA6IDEsIGVudGl0eUlkOiAxfQ==

Original issue: https://youtrack.haulmont.com/issue/PL-9444

Metadata

Metadata

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions