Here are the Parent and Child entity classes.
ParentCode:
import java.math.BigDecimal;
import java.sql.Timestamp;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
@Entity
@Table(name = "PARENT", uniqueConstraints = @UniqueConstraint(columnNames = {
"ASSOC_PARENT_1_ID", "ASSOC_PARENT_2_ID", "ASSOC_PARENT_3_ID" }))
public class FinanceSourceCreditLimit implements java.io.Serializable {
private long parentId;
private AssocParent1 assocParent1;
private AssocParent2 assocParent2;
private AssocParent3 assocParent3;
private BigDecimal decColumn1;
private Set<Child> childSet = new HashSet<>();
private long modifyById;
private Timestamp modifyTimstm;
public Parent() {
/**
* Any entity class must define a non-private zero-argument constructor
*/
}
public Parent(long parentId,
AssocParent1 assocParent1, AssocParent2 assocParent2,
AssocParent3 assocParent3, BigDecimal decColumn1, Set<Child> children,
long modifyById, Timestamp modifyTimstm) {
this.parentId = parentId;
this.assocParent1 = assocParent1;
this.assocParent2 = assocParent2;
this.assocParent3 = assocParent3;
this.decColumn1 = decColumn1;
this.children = children;
this.modifyById = modifyById;
this.modifyTimstm = modifyTimstm;
}
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "ParentIdGenerator")
@SequenceGenerator(name = "ParentIdGenerator", sequenceName = "SEQ_PARENT", allocationSize = 1)
@Column(name = "PARENT_ID", unique = true, nullable = false, precision = 10, scale = 0)
public long getParentId() {
return this.parentId;
}
public void setParentId(long parentId) {
this.parentId = parentId;
}
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "ASSOC_PARENT_1_ID", nullable = false)
public AssocParent1 getAssocParent1() {
return this.assocParent1;
}
public void setCreditLimitType(AssocParent1 assocParent1) {
this.assocParent1 = assocParent1;
}
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "ASSOC_PARENT_2_ID")
public AssocParent2 getAssocParent2() {
return this.assocParent2;
}
public void setAssocParent2(AssocParent2 assocParent2) {
this.assocParent2 = assocParent2;
}
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "ASSOC_PARENT_3_ID", nullable = false)
public AssocParent3 getAssocParent3() {
return this.assocParent3;
}
public void setAssocParent3(AssocParent3 assocParent3) {
this.assocParent3 = assocParent3;
}
@Column(name = "DEC_COL_1", precision = 10)
public BigDecimal getDecColumn1() {
return this.decColumn1;
}
public void setDecColumn1(BigDecimal decColumn1) {
this.decColumn1 = decColumn1;
}
@OneToMany(fetch = FetchType.LAZY, mappedBy = "parent")
@OptimisticLock(excluded=true)
public Set<Child> getChildren() {
return this.children;
}
public void setChildren(Set<Child> children) {
this.children = children;
}
@Column(name = "MODIFY_BY_ID", nullable = false, precision = 10, scale = 0)
public long getModifyById() {
return this.modifyById;
}
public void setModifyById(long modifyById) {
this.modifyById = modifyById;
}
@Version
@org.hibernate.annotations.Generated(GenerationTime.ALWAYS)
@org.hibernate.annotations.Source(SourceType.VM)
@Column(name = "MODIFY_TIMSTM", nullable = false)
public Timestamp getModifyTimstm() {
return this.modifyTimstm;
}
public void setModifyTimstm(Timestamp modifyTimstm) {
this.modifyTimstm = modifyTimstm;
}
}
ChildCode:
import java.sql.Timestamp;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Version;
@Entity
@Table(name = "Child")
public class Child implements java.io.Serializable {
private long childId;
private Parent parent;
private long modifyBy;
private Timestamp modifyTimstm;
public Child() {
/**
* Any entity class must define a non-private zero-argument constructor
*/
}
public Child(long childId, Parent parent, long modifyBy, Timestamp modifyTimstm) {
this.childId = childId;
this.parent = parent;
this.modifyBy = modifyBy;
this.modifyTimstm = modifyTimstm;
}
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQ_CHILD")
@SequenceGenerator(name = "SEQ_CHILD", sequenceName = "SEQ_CHILD", allocationSize = 1)
@Column(name = "CHILD_ID", unique = true, nullable = false, precision = 10, scale = 0)
public long getChildId() {
return this.childId;
}
public void setChildId(long childId) {
this.childId = childId;
}
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "PARENT_ID", nullable = true) //modified
//@JoinColumn(name = "PARENT_ID", nullable = false)
@OptimisticLock(excluded=true)
public Parent getParent() {
return this.parent;
}
public void setParent(Parent parent) {
this.parent = parent;
}
@Column(name = "MODIFY_BY", nullable = false, precision = 10, scale = 0)
public long getModifyBy() {
return this.modifyBy;
}
public void setModifyBy(long modifyBy) {
this.modifyBy = modifyBy;
}
@Version
@org.hibernate.annotations.Generated(GenerationTime.ALWAYS)
@org.hibernate.annotations.Source(SourceType.VM)
@Column(name = "MODIFY_TIMSTM", nullable = false)
public Timestamp getModifyTimstm() {
return this.modifyTimstm;
}
public void setModifyTimstm(Timestamp modifyTimstm) {
this.modifyTimstm = modifyTimstm;
}
}