-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: How do I mapping optional association collections parent and
PostPosted: Wed Oct 18, 2006 5:46 am 
Newbie

Joined: Thu Mar 03, 2005 5:09 am
Posts: 7
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)

Image

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 association
Criteria 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?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.