Hi all,
I am trying to filter a list of institutions based on a primary key and a joined tables address type (which is part of a composite key).
Code:
List institutionList = session.find("select mci from MainClientInfo as mci join mci.cuAddresss as cua where mci.pscuId = " + pscu_Id + " and cua.comp_id.cuAddrType = 'PH'");
This does return a single MainClientInfo object but its cuAddress set is populated with two objects when there should only be one. Each institution only has one address with an address type of 'PH'.
Can anyone see what I may be doing wrong ? Any help would be greatly appreciated.
MainClientInfo.hmb.xml
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<hibernate-mapping>
<!--
Created by the Middlegen Hibernate plugin
http://boss.bekk.no/boss/middlegen/
http://hibernate.sourceforge.net/
-->
<class
name="com.pscufs.servicesmanagement.hibernate.MainClientInfo"
table="MAIN_CLIENT_INFO"
schema="SA"
>
<id
name="pscuId"
type="java.math.BigDecimal"
column="PSCU_ID"
>
<generator class="sequence">
<param name="sequence">MAIN_CU_INFO_SEQ</param>
</generator>
</id>
<property
name="clientTypeCode"
type="java.lang.String"
column="CLIENT_TYPE_CODE"
not-null="true"
unique="true"
length="5"
/>
<property
name="institutionName"
type="java.lang.String"
column="INSTITUTION_NAME"
not-null="true"
length="80"
/>
<property
name="regionCode"
type="java.lang.String"
column="REGION_CODE"
not-null="true"
length="3"
/>
<property
name="clientStatusCode"
type="java.lang.String"
column="CLIENT_STATUS_CODE"
not-null="true"
length="2"
/>
<property
name="acctExecCode"
type="java.lang.String"
column="ACCT_EXEC_CODE"
not-null="true"
length="3"
/>
<property
name="startDate"
type="java.sql.Timestamp"
column="START_DATE"
length="7"
/>
<property
name="stopDate"
type="java.sql.Timestamp"
column="STOP_DATE"
length="7"
/>
<!-- associations -->
<!-- bi-directional one-to-one association to MainClientIdentifier -->
<one-to-one
name="mainClientIdentifier"
class="com.pscufs.servicesmanagement.hibernate.MainClientIdentifier"
outer-join="auto"
constrained="true"
/>
<!-- bi-directional one-to-many association to CuAddress -->
<set
name="cuAddresss"
lazy="false"
inverse="true"
>
<key>
<column name="PSCU_ID" />
</key>
<one-to-many
class="com.pscufs.servicesmanagement.hibernate.CuAddress"
/>
</set>
<!-- bi-directional one-to-many association to MainSpaInfo -->
<set
name="mainSpaInfos"
lazy="false"
inverse="true"
>
<key>
<column name="PSCU_ID" />
</key>
<one-to-many
class="com.pscufs.servicesmanagement.hibernate.MainSpaInfo"
/>
</set>
<!-- bi-directional one-to-many association to MainSpInfo -->
<set
name="mainSpInfos"
lazy="false"
inverse="true"
>
<key>
<column name="PSCU_ID" />
</key>
<one-to-many
class="com.pscufs.servicesmanagement.hibernate.MainSpInfo"
/>
</set>
</class>
</hibernate-mapping>
cuAddresss.hbm,.xml
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<hibernate-mapping>
<!--
Created by the Middlegen Hibernate plugin
http://boss.bekk.no/boss/middlegen/
http://hibernate.sourceforge.net/
-->
<class
name="com.pscufs.servicesmanagement.hibernate.CuAddress"
table="CU_ADDRESS"
schema="SA"
>
<composite-id name="comp_id" class="com.pscufs.servicesmanagement.hibernate.CuAddressPK">
<key-property
name="cuAddrType"
column="CU_ADDR_TYPE"
type="java.lang.String"
length="2"
/>
<!-- bi-directional many-to-one association to MainClientInfo -->
<key-many-to-one
name="mainClientInfo"
class="com.pscufs.servicesmanagement.hibernate.MainClientInfo"
column="PSCU_ID"
/>
</composite-id>
<property
name="addrLine1"
type="java.lang.String"
column="ADDR_LINE_1"
length="200"
/>
<property
name="city"
type="java.lang.String"
column="CITY"
length="30"
/>
<property
name="stateCode"
type="java.lang.String"
column="STATE_CODE"
not-null="true"
length="2"
/>
<property
name="zipPlusFour"
type="java.lang.String"
column="ZIP_PLUS_FOUR"
length="10"
/>
<property
name="addrLine2"
type="java.lang.String"
column="ADDR_LINE_2"
length="200"
/>
<property
name="country"
type="java.lang.String"
column="COUNTRY"
length="30"
/>
<!-- associations -->
</class>
</hibernate-mapping>
[/code]