The problem is that now there are two ways of updating the foreign key columns in the Customer entity, because the foreign key columns are present in the referenced District entity, but also present as fields in the entity in order to satisfy the requirements for a composite primary key. If you try to execute this code, you will encounter an Exception such as this (in Glassfish):
Multiple writable mappings exist for the field [TPCC.CUSTOMER.C_W_ID]. Only one may be defined as writable, all others must be specified read-only.
Multiple writable mappings exist for the field [TPCC.CUSTOMER.C_D_ID]. Only one may be defined as writable, all others must be specified read-only.
To resolve this problem, you need to modify the Customer Entity definition and ensure that the columns TPCC.CUSTOMER.C_W_ID and TPCC.CUSTOMER.C_D_ID are marked as readonly, by setting insertable=false and updatable=false:
EX. – OneToOne
tabA:
@OneToOne
@JoinColumn(name = "COMPANY_ID", referencedColumnName = "COMPANY_ID", unique=true, insertable=false, updatable=false)
private PlLogofile logofile;
tabB:
@Column(name="COMPANY_ID", unique=true)
private Long companyId;
EX: oneToMany-manyToOne
tabA:
@OneToMany(mappedBy = "partnerlocatorCompany")
private List<PlCompanyCrdChild> crdChilds;
tabB:
@ManyToOne
@JoinColumn(name = "COMPANY_ID", referencedColumnName = "COMPANY_ID", nullable=false,
insertable=false, updatable=false)
private PartnerlocatorCompany partnerlocatorCompany;
