用注解实现实体类的关系

一对一

@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 basTsUsers = new HashSet(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 basTsUsers = new HashSet(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 basTsRoles;

你可能感兴趣的:(注解)