[英]Retrieving a Set in Hibernate mapping in many-to-many
I want to get the outcomes set from the Complaint class which is a hibernate entity from the Complaints Table. 我想从投诉类中获取结果集,投诉类是投诉表中的休眠实体。 This table has a many-to-many relationship with a Table named Complaint_Outcome_Type and a join table named Complaint_Outcome. 该表与名为Complaint_Outcome_Type的表和名为Complaint_Outcome的联接表具有多对多关系。
Here is the Complaint and ComplaintOutcomeType classes 这是Complaint和ComplaintOutcomeType类
public class Complaint extends ComplaintBase{
private set<ComplaintOutcomeType> outcomes;
}
public class ComplaintOutcomeType {
private String code;
}
In ComplaintBase.hbm.xml I have 在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>
In ComplaintOutcomeType.hbm.xml I have 在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>
Here is my query string 这是我的查询字符串
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";
What I want to do is get the set of complaint outcomes for each complaint, so I can check if there is a complaint outcome of a particular type. 我要做的是获取每个投诉的投诉结果集,以便我可以检查是否存在特定类型的投诉结果。
eg complaint.getOutcomes().contains(ComplaintType ...); 例如投诉.getOutcomes()。包含(ComplaintType ...);
What do you use? 你用什么? If you use JPA, you can just get the list of complaint first like this: 如果您使用JPA,则可以首先获得投诉列表,如下所示:
String queryString = "select complaint from Complaint where complaint.subject.id = :complaintSubjectId";
it will return you a list of complaint. 它将返回您的投诉清单。 For each complaint, you can get the outcome set in the code: 对于每个投诉,您都可以在代码中获得结果集:
complaint.getOutcomes()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.