求助,jpa为含有复合主键如何建立一对多的关联
2014-12-20
展开全部
您好,很高兴为您解答:
@OneToMany(cascade = CascadeType.ALL , fetch = FetchType.LAZY)
@JoinColumn(name = "app_no")
public Set<NameAppInvest> getNameAppInvestsSet() {
return nameAppInvestsSet;
}
public void setNameAppInvestsSet(Set<NameAppInvest> nameAppInvestsSet) {
this.nameAppInvestsSet = nameAppInvestsSet;
}
这是我建立的一对多的关联
public void deleteApply(String appNo, int loadMode){
NameApp nameApp = null ;
if(StringUtils.isNotBlank(appNo)){
//得到名称申请案
nameApp = entityDAO.getNameApp(appNo);
}
if(nameApp != null){
if(loadMode == 0){
CascadeUtil.lazyInit(nameApp); // 加载全部Set
}
//删除名称申请案
entityDAO.deleteNameApp(nameApp);
}
}
希望以上信息可以帮到您!
@OneToMany(cascade = CascadeType.ALL , fetch = FetchType.LAZY)
@JoinColumn(name = "app_no")
public Set<NameAppInvest> getNameAppInvestsSet() {
return nameAppInvestsSet;
}
public void setNameAppInvestsSet(Set<NameAppInvest> nameAppInvestsSet) {
this.nameAppInvestsSet = nameAppInvestsSet;
}
这是我建立的一对多的关联
public void deleteApply(String appNo, int loadMode){
NameApp nameApp = null ;
if(StringUtils.isNotBlank(appNo)){
//得到名称申请案
nameApp = entityDAO.getNameApp(appNo);
}
if(nameApp != null){
if(loadMode == 0){
CascadeUtil.lazyInit(nameApp); // 加载全部Set
}
//删除名称申请案
entityDAO.deleteNameApp(nameApp);
}
}
希望以上信息可以帮到您!
2014-12-20
展开全部
进行面向对象的分析,uer和role之间是双向多对多联系,使用JPA配置如下所示:
@Entity
public class User implements Serizlizable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
private String userName;
private String passWord;
@ManyToMany(cascade = CascadeType.ALL)
private List<Role> roles;
......
......
}
@Entity
public class Role implements Serizlizable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
private String role;
@ManyToMany(mappedBy = "roles")
private User user;
......
......
}
配置后,会在数据库中生存你想要的3个表。
@Entity
public class User implements Serizlizable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
private String userName;
private String passWord;
@ManyToMany(cascade = CascadeType.ALL)
private List<Role> roles;
......
......
}
@Entity
public class Role implements Serizlizable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
private String role;
@ManyToMany(mappedBy = "roles")
private User user;
......
......
}
配置后,会在数据库中生存你想要的3个表。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询