Hi All,
I have mapped a many-to-many relation across a join table as follows,
The database structure is as follows
Case (1-M ) - CASE_CASE_PROFILE (M-1) - CODED_CASE_PROFILE
In the Case.hbm file, the set is mapped as follows:
Hibernate version:3.0
Mapping documents:
Code:
<class name="com.unyric.cias.cm.data.domain.Case" table="CASE">
<id name="id" type="java.lang.Long" column="CASE_ID">
<generator class="sequence">
<param name="sequence">CASE_SEQ</param>
</generator>
</id>
<property name="name" column="CASE_DESC" type="java.lang.String"/>
<set name="caseProfiles" table="CASE_CASE_PROFILE"
cascade="all-delete-orphan" lazy="true">
<key column="CASE_ID"/>
<many-to-many column="CASE_PROFILE_CODE" class="com.unyric.cias.cm.data.domain.type.CaseProfileType"/>
</set>
</class>
I am trying to query the caseProfiles i.e get all the Cases for a Coded_Profile type by using restrictions
I tried creating an ArrayList with the CaseProfileType however the join is on the CASE_ID column. I do not have the
middle object with the CASE_ID. Is it even possible to use restrictions or should I use some other way to implement this.
The main reason I need to use restrictions is this is one of the fields in a search screen with multiple
parameters.
Code:
List<CaseProfileType> caseProfilesList = new ArrayList<CaseProfileType>();
caseProfilesList.add(caseCriteria.getCaseProfileType());
Criteria criteria = session.createCriteria(CiasCase.class);
criteria.setFetchMode("caseProfiles", FetchMode.JOIN);
criteria.add(Restrictions.in( "caseProfiles",caseProfilesList ) );
Code:
select
this_.CASE_ID as CASE1_0_7_,
this_.CASE_DESC as CASE2_0_7_,
this_.CASE_NUM as CASE3_0_7_,
caseprofil5_.CASE_ID as CASE1_10_,
caseprofil6_.CASE_PROFILE_CODE as CASE2_10_,
caseprofil6_.CASE_PROFILE_CODE as CASE1_16_3_,
agency9_.ADDRESS_ID as ADDRESS6_58_6_
from
CASE this_
left outer join
CASE_CASE_PROFILE caseprofil5_
on this_.CASE_ID=caseprofil5_.CASE_ID
left outer join
CODED_CASE_PROFILE caseprofil6_
on caseprofil5_.CASE_PROFILE_CODE=caseprofil6_.CASE_PROFILE_CODE
where
this_.CASE_ID in (
?
)
Thanks in advance for any help, and please pardon if its not clear.