First, I'm not good at English so I hope you understood my mistake.
I have two tables and associate bi-direct between GroupSalesGoal(Parent) and SalesGoal(Child)
I want access some child of whole collections from parent by set collection
for example
parent get collection of child goal_month is '200610' in group_id='0103' and goal_item={'sales', 'adv', 'tax'}
so, how do I mapped ?
Hibernate version:3.0
Mapping documents:
1. SalesGoalItem.hbm.xml
Code:
<hibernate-mapping>
<class
name="SalesGoalItem"
table="Sales_Goal_Item"
lazy="false"
>
<composite-id name="comp_id" class="SalesGoalItemPK">
<key-property
name="groupId"
column="group_id"
type="java.lang.String"
length="10"
/>
<key-property
name="goalItem"
column="goal_Item"
type="java.lang.String"
length="16"
/>
</composite-id>
<property
name="itemName"
type="java.lang.String"
column="item_name"
length="30"
/>
<!-- Associations -->
<set name="salesGoals" lazy="true" inverse="true">
<key>
<column name="group_id" />
<column name="goal_item" />
</key>
<one-to-many class="SalesGoal" />
</set>
<!-- derived association(s) for compound key -->
<!-- end of derived association(s) -->
</class>
</hibernate-mapping>
2. SalesGoal.hbm.xml
Code:
<hibernate-mapping>
<class
name="SalesGoal"
table="Sales_Goal"
lazy="false"
>
<meta attribute="implement-equals" inherit="false">true</meta>
<composite-id name="comp_id" class="SalesGoalPK">
<key-property
name="goalDate"
column="goal_date"
type="java.lang.String"
length="6"
/>
<key-property
name="groupId"
column="group_id"
type="java.lang.String"
length="10"
/>
<key-property
name="goalItem"
column="goal_Item"
type="java.lang.String"
length="16"
/>
</composite-id>
<property
name="goalAmt"
type="java.math.BigDecimal"
column="GOAL_AMT"
not-null="true"
length="22"
/>
<!-- Associations -->
<!-- derived association(s) for compound key -->
<!-- end of derived association(s) -->
</class>
</hibernate-mapping>
two mapping file is normal one-to-many associationCriteria Code:Code:
session.createCriteria(SalesGoalItem.class)
.add(Restrictions.eq("comp_id.groupId", "0103")
.createCriteria("salesGoals")
.add(Restrictions.eq("comp_id.goal_date", "200610")
.list();
select SalesGoalItem obect but use in web page
SalesGoalItem.salesGoals have all of child data (that goal_date from 200601 to 200610)
just I want SalesGoalItem.salesGoals have only one data of goal_date value is "200610"
[also child data can be null like left outer join ]
How do I this ?
I don't want get child like this
Code:
session.createCriteria(SalesGoal.class)
.add(Restrictions.eq("comp_id.groupId", "0103")
.add(Restrictions.eq("comp_id.goal_date", "200610")
.list();
because there is no child data for goal_date is "200610"
but I want view parent data of each Items("sales", "adv", "tax") like left outer join.
Want
1. get collections optional with child property value(goal_date)
2. get colledtions like left outer join if child data is empty.
Is there any ideas?