I have 3 tables (Table 1, Table 2, Table 3). Table 1 is related to Table 2 by @onetomany using primary key. Table 2 is related to Table 3 by @manytoone. Table 2 has EmbeddedId.
When I get the details using Table 1's primary key, I am able to fetch the data in Table 2 and Table 3. But I can't do save and delete. Save and delete is happening on the Table 1's child table (ie Table 2), but does not impact Table 3(which is child to Table 2)
Below are the entity models of all the three tables
@Entity
@Table(name = "FEATUREMASTER")
@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
public class FeatureMaster implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
@Id
@Column(name = "FGID")
private String featureid;
@Column(name = "FEATURENAME", nullable = false, unique = false)
private String featurename;
@Column(name = "DESCRIPTION", nullable = true, unique = false)
private String description;
@Column(name = "LIBNAME", nullable = true, unique = false)
private String libname;
@Column(name = "ISENABLED", nullable = false, unique = false)
private String isenabled;
@Column(name = "EDRULEGRP", nullable = true, unique = false)
private String edrulegrp;
// Do Not use - [orphanRemoval = true & CascadeType.ALL]- If used, deletion is not happening
@OneToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE})
@JoinColumn(name = "FGID")
private List<CfgMaster> parameters;
// Getters and Setters
}
@Entity
@Table(name = "CFGMASTER")
public class CfgMaster implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
@EmbeddedId
private CfgMasterPK id;
@Column(name = "CONFIGNAME", length = 45, nullable = true, unique = false)
private String parameter_name;
@Column(name = "CONFIGTYPE", length = 20, nullable = true, unique = false)
private String type;
@Column(name = "SUBPARAM", nullable = true, unique = false)
private Integer subparam;
@Column(name = "CONFIGDESCRIPTION", nullable = true, unique = false)
private String description;
@Column(name = "CONFIGLIMITFROM", nullable = true, unique = false)
private String from;
@Column(name = "CONFIGLIMITTO", nullable = true, unique = false)
private String to;
@ManyToOne(cascade = {CascadeType.ALL}, optional = true, fetch = FetchType.LAZY )
// @ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE}, fetch = FetchType.LAZY)
@NotFound(action=NotFoundAction.IGNORE) // This is required to handle when no CfgData is found
@JoinColumns({
@JoinColumn(name = "FGID", insertable = false, updatable = false),
@JoinColumn(name = "DATAKEY", insertable = false, updatable = false)
})
private CfgData cfgData;
//Getters and Setters
}
@Entity
@Table(name = "CFGDATA")
public class CfgData implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
/*@EmbeddedId
private CfgDataPK id;*/
@Id
@Column(name = "FGID")
private String fgid;
@Id
@Column(name = "DATAKEY")
private String datakey;
@Column(name = "EPID", nullable = false, unique = false)
private int epid;
@Column(name = "RESERVED1", length = 45, nullable = true, unique = false)
private String reserved1;
@Column(name = "VALUE1", length = 100, nullable = true, unique = false)
private String value1;
@Column(name = "VALUE2", length = 100, nullable = true, unique = false)
private String value2;
//Getters and Setters
}
The problem I am facing is, I am not able to delete/save the entities of CfgData by passing FeatureMaster's primary id. Any operation I do is affecting only parent &child, not the grand child (CfgData) I tried a lot googling, but I cant find the solution.