I'm working on legacy system, need to read some of the info from database. Below are the table relationship
Vendor (vendorId - pk, vendorEid, name)
VendorContactBridge (bridgeId -pk, vendorEid, contactEid)
Contact (contactId -pk, contactEid, phone)
vendorEid and contactEid are not the primary key of the table but used as join column in Join table VendorContactBridge.
Vendor Entity -
@Entity
@Table(name="Vendor")
public class Vendor implements Serializable{
@Id
@Column(name="VENDORID")
private BigDecimal vendorId;
@Column(name="VENDOREID")
private BigDecimal vendorEid;
@OneToMany(fetch = FetchType.EAGER)
@JoinTable(name="VENDORCONTACTBRIDGE",
joinColumns={@JoinColumn(name="VENDOREID", referencedColumnName="VENDOREID")},
inverseJoinColumns={@JoinColumn(name="CONTACTEID", referencedColumnName="CONTACTEID")})
private Set<Contact> vendorContact;
}
Contact Entity -
@Entity
@Table(name="CONTACT")
public class Contact implements Serializable{
@Id
@Column(name="CONTACTID")
private BigDecimal contactId;
@Column(name="CONTATEID")
private BigDecimal contactEId;
@ManyToOne
@JoinTable(name="VENDORCONTACTBRIDGE",
joinColumns={@JoinColumn(name="CONTACTEID", referencedColumnName="CONTATEID")},
inverseJoinColumns={@JoinColumn(name="VENDOREID", referencedColumnName="VENDOREID")})
private Vendor vendor;
}
while running the query, getting below exception
SecondaryTable JoinColumn cannot reference a non primary key.
I removed the Eager fetch which i have given in Vendor entity, i dont get any exception but it doesn't load the collection. What's wrong with association ?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…