在多对多映射中检索 Hibernate 中的集合
Retrieving a Set in Hibernate mapping in many-to-many
我想从 Complaint class 中获取结果集,它是来自 Complaints Table 的休眠实体。此 table 与名为 Complaint_Outcome_Type 的 Table 和名为 Complaint_Outcome.
的连接 table 具有多对多关系
这是投诉和投诉结果类型 classes
public class Complaint extends ComplaintBase{
private set<ComplaintOutcomeType> outcomes;
}
public class ComplaintOutcomeType {
private String code;
}
在ComplaintBase.hbm.xml我有
<class name="registrationdb.domain.ComplaintBase" table="COMPLAINT_BASE">
...
<joined-subclass name="registrationdb.domain.Complaint" table="COMPLAINT">
<key>
<column name="COMPLAINT_ID"/>
</key>
...
<set name="outcomes" table="COMPLAINT_OUTCOME" >
<key column="COMPLAINT_ID" not-null="true"/>
<many-to-many column="CODE" class="registrationdb.domain.reference.ComplaintOutcomeType" />
</set>
...
</class>
在ComplaintOutcomeType.hbm.xml我有
<class name="registrationdb.domain.reference.ComplaintOutcomeType" table="COMPLAINT_OUTCOME_TYPE">
<id name="code" type="string" column="CODE" />
<property name="description" type="string" column="DESCRIPTION" />
<property name="displaySequence" type="integer" column="DISPLAY_SEQUENCE" />
</class>
这是我的查询字符串
String queryString = "select complaint.id, complaint.subject, complaint.complainant, complaint.openedDate, complaint.closedDate ";
queryString = queryString + "from registrationdb.domain.Complaint as complaint ";
queryString = queryString + "where complaint.subject.id = :complaintSubjectId and complaint.outcomes";
我想做的是获取每个投诉的投诉结果集合,这样我就可以检查是否有特定类型的投诉结果。
例如complaint.getOutcomes().contains(投诉类型...);
你用什么?如果你使用JPA,你可以像这样先获取投诉列表:
String queryString = "select complaint from Complaint where complaint.subject.id = :complaintSubjectId";
它会return给你一份投诉清单。每一次投诉,您都可以得到代码中设置的结果:
complaint.getOutcomes()
我想从 Complaint class 中获取结果集,它是来自 Complaints Table 的休眠实体。此 table 与名为 Complaint_Outcome_Type 的 Table 和名为 Complaint_Outcome.
的连接 table 具有多对多关系这是投诉和投诉结果类型 classes
public class Complaint extends ComplaintBase{
private set<ComplaintOutcomeType> outcomes;
}
public class ComplaintOutcomeType {
private String code;
}
在ComplaintBase.hbm.xml我有
<class name="registrationdb.domain.ComplaintBase" table="COMPLAINT_BASE">
...
<joined-subclass name="registrationdb.domain.Complaint" table="COMPLAINT">
<key>
<column name="COMPLAINT_ID"/>
</key>
...
<set name="outcomes" table="COMPLAINT_OUTCOME" >
<key column="COMPLAINT_ID" not-null="true"/>
<many-to-many column="CODE" class="registrationdb.domain.reference.ComplaintOutcomeType" />
</set>
...
</class>
在ComplaintOutcomeType.hbm.xml我有
<class name="registrationdb.domain.reference.ComplaintOutcomeType" table="COMPLAINT_OUTCOME_TYPE">
<id name="code" type="string" column="CODE" />
<property name="description" type="string" column="DESCRIPTION" />
<property name="displaySequence" type="integer" column="DISPLAY_SEQUENCE" />
</class>
这是我的查询字符串
String queryString = "select complaint.id, complaint.subject, complaint.complainant, complaint.openedDate, complaint.closedDate ";
queryString = queryString + "from registrationdb.domain.Complaint as complaint ";
queryString = queryString + "where complaint.subject.id = :complaintSubjectId and complaint.outcomes";
我想做的是获取每个投诉的投诉结果集合,这样我就可以检查是否有特定类型的投诉结果。
例如complaint.getOutcomes().contains(投诉类型...);
你用什么?如果你使用JPA,你可以像这样先获取投诉列表:
String queryString = "select complaint from Complaint where complaint.subject.id = :complaintSubjectId";
它会return给你一份投诉清单。每一次投诉,您都可以得到代码中设置的结果:
complaint.getOutcomes()