[英]Retrieving a Set in Hibernate mapping in many-to-many
我想從投訴類中獲取結果集,投訴類是投訴表中的休眠實體。 該表與名為Complaint_Outcome_Type的表和名為Complaint_Outcome的聯接表具有多對多關系。
這是Complaint和ComplaintOutcomeType類
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";
我要做的是獲取每個投訴的投訴結果集,以便我可以檢查是否存在特定類型的投訴結果。
例如投訴.getOutcomes()。包含(ComplaintType ...);
你用什么? 如果您使用JPA,則可以首先獲得投訴列表,如下所示:
String queryString = "select complaint from Complaint where complaint.subject.id = :complaintSubjectId";
它將返回您的投訴清單。 對於每個投訴,您都可以在代碼中獲得結果集:
complaint.getOutcomes()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.