There is a JPA entity for which the one-to-many relationship is defined:

@Entity @Table(name = "organization") @JsonIgnoreProperties(value = {"hibernateLazyInitializer", "handler"}, ignoreUnknown = true) public class Organization extends BlockchainEntity { @Id @Column(name = "msp") @JsonProperty("msp") private String msp; @Column(name = "signers") @JsonProperty("signers") @OneToMany(mappedBy = "organization", cascade = CascadeType.ALL) private List<Certificate> signers; } 

And JPA-class certificates:

 @Entity @IdClass(Certificate.CertificatePK.class) @Table(name = "certificate", indexes = {}) public class Certificate { @Id @Column(name = "msp") @JsonProperty("MSP") private String msp; @Id @Column(name = "fingerprint") @JsonProperty("fingerprint") private String fingerprint; @ManyToOne @JoinColumn(name = "msp", referencedColumnName = "msp", nullable = false) private Organization organization; } 

A table with no extra fields is defined as:

 create table if not exists certificate ( fingerprint varchar(255) not null, msp varchar not null, active boolean, foreign key (msp) references organization(msp), constraint certificate_pkey primary key (fingerprint, msp) ); 

That is, the table has a primary composite key (fingerprint, msp) and at the same time the msp field must be a foreign key to the organization table.

How to do this technically? When I run the application, I get an exception:

Caused by: org.hibernate.MappingException: Repeated column: core.entities.certificate.Certificate column: msp (should be mapped with insert = "false" update = "false")

The table certificate filled regardless of the organization table.

    1 answer 1

    Well, add insertable = false, updatable = false to @JoinColumn