Hello, Could you give me any hint for solving my problem?
- I have 2 tables. : ImportBase, ImportDetail
ImportBase have 3 compoiste primary key. : VESSEL_CODE, TERMINAL_REF_NO, TERMINAL
ImportDetail have 4 composite primary key. : VESSEL_CODE, TERMINAL_REF_NO, TERMINAL, CONTAINER_NO
ImportDetail have 3 composite foreign key. : VESSEL_CODE, TERMINAL_REF_NO, TERMINAL
- I have 2 job to do.
First job is 'mapin' that is inserting 1 row of ImportBase and many rows of ImportDetail to db.
Second job is 'mapout' that is selecting 1 row of ImportBase and 1 row of ImportDetail by VESSEL_CODE, TERMINAL_REF_NO, TERMINAL + 'CONTAINER_NO' from db.
- Problem
'mapin' is ok. but when mapout, I can't get 1 row of ImportBase and 1 row of ImportDetail.
I just get 1 row of ImportBase and many rows of ImportDetail.
I tried to make HQL with 'CONTAINER_NO' to get 1 row of ImportDetail, but failed.
How can I get 1 row of ImportDetail by 'CONTAINER_NO' from one-to-many relation?
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
[b]Mapping documents: [/b]
1. ImportBase ==================================================================
<hibernate-mapping>
<!--
Created by the Middlegen Hibernate plugin 2.2
http://boss.bekk.no/boss/middlegen/
http://www.hibernate.org/
-->
<class
name="com.klnet.model.coarri.ImportBase"
table="TEST_IMPORT_BASE"
>
<composite-id name="comp_id" class="com.klnet.model.coarri.ImportBasePK" unsaved-value="undefined">
<key-property
name="vesselCode"
column="VESSEL_CODE"
type="java.lang.String"
length="12"
/>
<key-property
name="terminalRefNo"
column="TERMINAL_REF_NO"
type="java.lang.String"
length="9"
/>
<key-property
name="terminal"
column="TERMINAL"
type="java.lang.String"
length="15"
/>
</composite-id>
<property
name="vesselName"
type="java.lang.String"
column="VESSEL_NAME"
length="51"
/>
<property
name="carrierRefNo"
type="java.lang.String"
column="CARRIER_REF_NO"
length="18"
/>
<!-- Associations -->
<!-- derived association(s) for compound key -->
<!-- end of derived association(s) -->
<!-- bi-directional one-to-many association to ImportDetail -->
<set
name="importDetails"
lazy="false"
inverse="true"
cascade="all"
>
<key>
<column name="VESSEL_CODE" />
<column name="TERMINAL_REF_NO" />
<column name="TERMINAL" />
</key>
<one-to-many
class="com.klnet.model.coarri.ImportDetail"
/>
</set>
</class>
<query name="selectCOARRI"><![CDATA[
from ImportBase g
where g.comp_id.vesselCode = :cond1
and g.comp_id.terminalRefNo = :cond2
and g.comp_id.terminal = :cond3
]]>
</query>
</hibernate-mapping>
=================================================================================
2. ImportDetail ==================================================================
<hibernate-mapping>
<!--
Created by the Middlegen Hibernate plugin 2.2
http://boss.bekk.no/boss/middlegen/
http://www.hibernate.org/
-->
<class
name="com.klnet.model.coarri.ImportDetail"
table="TEST_IMPORT_DETAIL"
>
<composite-id name="comp_id" class="com.klnet.model.coarri.ImportDetailPK">
<key-property
name="vesselCode"
column="VESSEL_CODE"
type="java.lang.String"
length="12"
/>
<key-property
name="terminalRefNo"
column="TERMINAL_REF_NO"
type="java.lang.String"
length="9"
/>
<key-property
name="terminal"
column="TERMINAL"
type="java.lang.String"
length="15"
/>
<key-property
name="containerNo"
column="CONTAINER_NO"
type="java.lang.String"
length="33"
/>
</composite-id>
<property
name="portCode"
type="java.lang.String"
column="PORT_CODE"
length="15"
/>
<property
name="routeCode"
type="java.lang.String"
column="ROUTE_CODE"
length="6"
/>
<!-- Associations -->
<!-- derived association(s) for compound key -->
<!-- bi-directional many-to-one association to ImportBase -->
<many-to-one
name="importBase"
class="com.klnet.model.coarri.ImportBase"
update="false"
insert="false"
lazy="false"
fetch="join"
>
<column name="VESSEL_CODE" />
<column name="TERMINAL_REF_NO" />
<column name="TERMINAL" />
</many-to-one>
<!-- end of derived association(s) -->
</class>
</hibernate-mapping>
=================================================================================