Hi All,
I have a parent child relation ship in my db and I am trying to save data.Data gets properly saved into parent table but it does not get saved into child table.
I have defined OneToMany relation in parent table and ManyToOne in child table.All of import statements are importing javax.persistence classes (can that be an issue?).
Another thing is that child class is child of two classes(It has two columns that have ManyToOne relations).Is that an issue?
Parent class :-
Code:
@Entity
@Table(name = "CSO_PROFILE")
@XmlRootElement
public class CsoProfile implements Serializable {
private int csoProfileId;
private String csoProfileName;
private String defaultProfile;
private String langPair;
private int transEngineProfileMapId;
private String customerName;
private List<CustomerCsoProfileMap> customerCsoProfileMapList;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "csoProfileId")
public List<CustomerCsoProfileMap> getCustomerCsoProfileMapList() {
return customerCsoProfileMapList;
}
public void setCustomerCsoProfileMapList(List<CustomerCsoProfileMap> customerCsoProfileMapList) {
this.customerCsoProfileMapList = customerCsoProfileMapList;
}
Child class -
Code:
@Entity
@Table(name = "CUSTOMER_CSO_PROFILE_MAP")
@XmlRootElement
public class CustomerCsoProfileMap {
private int customerCsoProfilemapId;
private Customer customerID;
private CsoProfile csoProfileId;
@SequenceGenerator(name = "CustCsoProfile_Gen", sequenceName = "customer_cpm_sequence")
@Id
@GeneratedValue(generator = "CustCsoProfile_Gen")
@Basic(optional = false)
@Column(name = "CUSTOMER_CSO_PROFILE_MAP_ID")
public int getCustomerCsoProfilemapId() {
return customerCsoProfilemapId;
}
public void setCustomerCsoProfilemapId(int customerCsoProfilemapId) {
this.customerCsoProfilemapId = customerCsoProfilemapId;
}
@JoinColumn(name = "CUSTOMER_ID", referencedColumnName = "CUSTOMER_ID")
@ManyToOne(optional = false)
public Customer getCustomerID() {
return customerID;
}
public void setCustomerID(Customer customerId) {
this.customerID = customerId;
}
@JoinColumn(name = "CSO_PROFILE_ID", referencedColumnName = "CSO_PROFILE_ID")
@ManyToOne(optional = false)
public CsoProfile getCsoProfileId() {
return csoProfileId;
}
public void setCsoProfileId(CsoProfile csoProfileId) {
this.csoProfileId = csoProfileId;
}
}
Data should be saved in CustomerCsoProfileMap when data is inserted in CsoProfile.There is no error in logs.
What am I doing wrong?