我是wicket-hibernate开发的新手。我有以下情况,但我不确定如何通过wicket实现它。
我有一个包含以下值的角色表
1名买家
2通知程序
3 EmailRecipient
我有一个PersonRelation表,其中包含以下详细信息
1 112
2 113
这里的人是一个引用人员表的外键。人员关系和角色表之间存在多对多的关系。
wicket表单在前端包含“角色表描述”作为复选框。每当用户点击复选框时,应该相应地更新多对多关系表。请让我知道如何通过wicket-spring-hibernate实现它。感谢您的帮助以解决此问题。
PFA是hibernate类的代码。
@Entity
public class PeopleRelation implements DaoFunPortalObject {
@Id
@GeneratedValue
@Column(name = "PeopleRelation_id")
private Long id;
@ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "People")
private People people;
@Column(name = "relationship")
private String relation;
@ManyToMany(cascade=CascadeType.PERSIST)
@JoinTable(
name = "PeopleRelation_Role",
joinColumns={@JoinColumn(name = "PeopleRelation_id")},
inverseJoinColumns={@JoinColumn(name = "Role_id")}
)
private Set<Role> roles = new HashSet<Role>();
public PeopleRelation() {
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public People getPeople() {
return people;
}
public void setPeople(People people) {
this.people = people;
}
public String getRelationship() {
return relation;
}
public void setRelationship(String relation) {
this.relation = relation;
}
public String getRelation() {
return relation;
}
public void setRelation(String relation) {
this.relation = relation;
}
public Set<Role> getRoles() {
return roles;
}
public void setRoles(Set<Role> roles) {
this.roles = roles;
}
}
@Entity
public class Role implements DaoFunPortalObject{
@Id
@GeneratedValue
@Column(name = "Role_id")
private Long id;
private String description;
@ManyToMany(mappedBy="roles")
private Set<PeopleRelation> peopleRelations = new HashSet<PeopleRelation>();
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Set<PeopleRelation> getPeopleRelations() {
return peopleRelations;
}
public void setPeopleRelations(Set<PeopleRelation> peopleRelations) {
this.peopleRelations = peopleRelations;
}
}
Wicket前端
personForm.add(new DropDownChoice<String>("state",
new PropertyModel<String>(people, "state"), statesList));
personForm.add(new TextField<String>("zip",
new PropertyModel<String>(people, "zip")));
personForm.add(new CheckBoxMultipleChoice<String>(
"roles", new Model(roleSelect), roleList));
答案 0 :(得分:0)
在hibernate中,你必须有一个新的会话才能检索和保存数据。通常在Web应用程序中,您在请求开始时打开会话,并在结束时关闭它。 Spring有一个OpenSessionInViewFilter,它是一个servlet过滤器,应该在wicket应用程序之前放在过滤器链中。它在请求开始时打开hibernate会话,并在结束时关闭它。所有这些都对您的应用程序代码透明地发生。
在你的问题中,你不清楚你遇到了什么问题。您的解决方案是否导致错误消息?如果是这样的话是什么?
希望这有帮助!