1)
2)
@Entity
@Table(name = "UT_PARENT")
public class ParentObject {
private int id;
private String value;
private Set<ChildObject> children;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "ID", precision = 19, scale = 0)
public int getId() {
return id;
}
//mappedBy refer to the property name of Child.parent
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, targetEntity=ChildObject.class, mappedBy="parentObject")
public Set<ChildObject> getChildren() {
return children;
}
}
2)
@Entity
@Table(name = "UT_CHILD")
public class ChildObject {
private int id;
private String value;
private ParentObject parentObject;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "ID", precision = 19, scale = 0)
public int getId() {
return id;
}
@ManyToOne(cascade = { CascadeType.PERSIST, CascadeType.MERGE }, targetEntity=ParentObject.class)
@JoinColumn(name = "UT_PRAENT_ID", insertable = false, updatable = false)
public ParentObject getParentObject() {
return parentObject;
}
}