一对一
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "THEMEID")
@Cascade({CascadeType.ALL})
private BasTsTheme basTsTheme;
一对多
@OneToMany( fetch = FetchType.LAZY, mappedBy = "basTsGrade")
@Cascade({CascadeType.DELETE_ORPHAN,CascadeType.SAVE_UPDATE})
private Set<BasTsUser> basTsUsers = new HashSet<BasTsUser>(0);
多对一
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "GRADEID")
@Cascade({CascadeType.SAVE_UPDATE})
private BasTsGrade basTsGrade;
多对多
@ManyToMany( fetch = FetchType.LAZY, mappedBy = "basTsRoles")
@Cascade({CascadeType.DELETE_ORPHAN,CascadeType.SAVE_UPDATE})
private Set<BasTsUser> basTsUsers = new HashSet<BasTsUser>(0);
@ManyToMany( fetch = FetchType.LAZY)
@JoinTable(name = "BAS_TR_ROLEUSER", schema = "DESK", joinColumns = { @JoinColumn(name = "USERID", nullable = false, updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "ROLEID", nullable = false, updatable = false) })
@Cascade({ CascadeType.DELETE_ORPHAN, CascadeType.SAVE_UPDATE })
private Set<BasTsRole> basTsRoles;
简单解释下,在一对一关系中,每个用户只有一个主题,通过themeid关联
一对多和多对一结合起来看,grade即会员等级,一个会员只能有一个等级,一个等级有多个会员。
多对多是典型的用户和角色关系,不解释