-->
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.  [ 3 posts ] 
Author Message
 Post subject: "left fetch join" supposed to work like this?
PostPosted: Mon Mar 01, 2004 7:16 am 
Pro
Pro

Joined: Wed Oct 08, 2003 10:31 am
Posts: 247
I'm using Hibernate 2.1.1.
My mapping files were generated with Middlegen R3.

------------------
Mapping file
------------------

MpRequisicaoSq044
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 Middlegen Hibernate plugin

    http://boss.bekk.no/boss/middlegen/
    http://hibernate.sourceforge.net/
-->

<class
    name="vo.MpRequisicaoSq044"
    table="mp_requisicao_sq044"
>

    <id
        name="id"
        type="long"
        column="id"
    >
        <generator class="increment" />
    </id>

    <property
        name="dataRequisicao"
        type="java.sql.Date"
        column="data_requisicao"
        not-null="true"
        length="4"
    />
    <property
        name="estado"
        type="java.lang.String"
        column="estado"
        length="1"
    />
   
    <!-- associations -->
    <!-- bi-directional one-to-many association to MpReqItem -->
    <set
        name="mpReqItems"
        lazy="true"
        inverse="true"
    >
        <key>
            <column name="mp_requisicao_fk" />
        </key>
        <one-to-many
            class="vo.MpReqItem"
        />
    </set>

</class>
</hibernate-mapping>


------------------
Method code
------------------
Code:
( ... )
List res = session.find("from vo.MpRequisicaoSq044 mr left join fetch mr.mpReqItems order by mr.dataRequisicao");
( ... )


---------------------------
Output (System.out)
---------------------------
Code:
----- MP_REQUISICAO -----
ID: 2 + DATA: 2004-02-20
----- MP_REQ_ITEM -----
ID: 2 + QTD: 200
ID: 2 + QTD: 100
------------------------------------
----- MP_REQUISICAO -----
ID: 2 + DATA: 2004-02-20
----- MP_REQ_ITEM -----
ID: 2 + QTD: 200
ID: 2 + QTD: 100
------------------------------------
----- MP_REQUISICAO -----
ID: 4 + DATA: 2004-02-27
----- MP_REQ_ITEM -----
ID: 4 + QTD: 200
ID: 4 + QTD: 300
------------------------------------
----- MP_REQUISICAO -----
ID: 4 + DATA: 2004-02-27
----- MP_REQ_ITEM -----
ID: 4 + QTD: 200
ID: 4 + QTD: 300
------------------------------------


In my output, MP_REQUISICAO is being repeated the number of times that MP_REQ_ITEM appears in its set's.
Shouldn't "left fetch join" retrieve a list of uniqueMpRequisicaoSq044 with each "set" initialized with the corresponding mpReqItems objects?


Please help. Need to know because it has some impact on project.
And if this is the normal behaviour, then what's the workarround.

Thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 01, 2004 7:18 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
http://www.hibernate.org/74.html#A7


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 01, 2004 7:22 am 
Pro
Pro

Joined: Wed Oct 08, 2003 10:31 am
Posts: 247
michael wrote:


Amazed by the fast reply. :)

What's the normal workarround?
Using the Criteria interface can obtain the expected result?


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

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.