Hi every One, I have these class :
@Entity
@Table(name = "branch", uniqueConstraints = {@UniqueConstraint(columnNames = {"bname", "branch_fk"})})
public class BranchEntity implements Serializable {
@Id
@GeneratedValue
private int id;
@Column(name = "username", length = 64, nullable = false)
private String userName;
@Column(name = "bname", length = 64)
private String branchName;
@Column(name = "studcount")
private int studCount;
@Column(name = "blevel", columnDefinition = "int default 0")
private int level;
@Column(name = "confirmed", columnDefinition = "tinyint default 0")
private int confirmed;
@OneToMany(mappedBy = "branch", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@OnDelete(action = OnDeleteAction.CASCADE)
@Cascade(org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
private Set<BranchBuildingEntity> branchbuilding = new HashSet<BranchBuildingEntity>();
@OneToMany(mappedBy = "branch", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@OnDelete(action = OnDeleteAction.CASCADE)
@Cascade(org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
private Set<PictureEntity> picture = new HashSet<PictureEntity>();
@OneToOne(mappedBy = "branch", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@OnDelete(action = OnDeleteAction.CASCADE)
@Cascade(org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
private LoginEntity login;
@OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
@JoinColumn(name = "human_fk", nullable = true)
private HumanEntity human;
//some setter and getter
As you can see these table have relation with HumnEntity and PictureEntity and ... table. in my domain layer I have Branch class that was dependant on Branch table and all of it's relation. when domain Pass a Branch Object and I want change the Branch in Database I have some Problem that explain below. In Domain Layer in Human class I don't have Identifier(Primary Key) then when I want SaveOrUpdate(branchEntity) I must set all attribute but when I want set branchEntity.setHumanEntity I must query again and get Identifier from database and set to humanEntity then set branchEntity.setHumanEntity. I wanna know that was right? or I do wrong some where ? am I must keep HumanEntity Identifier in My Human class in domain Layer? Indeed I don't know what exactly happen when save or SaveOrUpdate or Update or ... and Object that have RElation with other Object? how I must handle that Object?