One-to-many:
@Entity(name = "parent")
@Access(AccessType.FIELD)
public class Parent {
@OneToMany(fetch = FetchType.LAZY, mappedBy="childVarName", orphanRemoval=true)
protected Set<Child> parentVarName;
}
@Entity(name = "child")
@Access(AccessType.FIELD)
public class Child {
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "child", nullable = false)
protected Parent childVarName;
}
One-to-one:
public class VirtualParent { @OneToOne(mappedBy = "
") protected
virtualParentVar
VirtualChild
virtualChild
Var; // ... } public class
VirtualChild
{ @OneToOne @JoinColumn(name = "frn_
virtual_parent
_id") protectedVirtualParent
; // ... }
virtualParentVar
Many-to-many:
No comments:
Post a Comment