I have 2 model/annotated classes, ProductDetails and VnfDetails. I want to join the 2 tables with @OnetoMany relation using JPA HIbernate
ProductDetails model class is below with @OnetoMany Mapping:
@Entity
@Table(name="product_details")
public class ProductDetails {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name="ID")
private int id;
@Column(name="PRODUCT_ID")
private String productId;
@Column(name="PRODUCT_NAME")
private String productName;
@OneToMany(mappedBy="productDetails", cascade=CascadeType.ALL)
private Set<VnfDetails> vnfd;
public Set<VnfDetails> getVnfd() {
return vnfd;
}
public void setVnfd(Set<VnfDetails> vnfd) {
this.vnfd = vnfd;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getProductId() {
return productId;
}
public void setProductId(String productId) {
this.productId = productId;
}
public String getProductName() {
return productName;
}
public void setProductName(String productName) {
this.productName = productName;
}
VnfDetails is below having @ManytoOne with JoinColumn:
@Entity
@Table(name="vnf_details")
public class VnfDetails {
@Id
@Column(name="VNF_ID")
private String vnfId;
@Column(name="VNF_NAME")
private String vnfName;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name="PRODUCT_ID")
private ProductDetails productDetails;
public ProductDetails getProductDetails() {
return productDetails;
}
public void setProductDetails(ProductDetails productDetails) {
this.productDetails = productDetails;
}
public String getVnfId() {
return vnfId;
}
public void setVnfId(String vnfId) {
this.vnfId = vnfId;
}
public String getVnfName() {
return vnfName;
}
public void setVnfName(String vnfName) {
this.vnfName = vnfName;
}
when I am inserting data, the data is getting inserted but the PRODUCT_ID in VnfDetails table is null.
It should be the foreign key having "ID" of PRODUCT_DETAILS table.
Unable to resolve the issue.