Multiple mapping table – SQL

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;

发表评论

Filed under Uncategorized

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Connecting to %s