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.  [ 4 posts ] 
Author Message
 Post subject: Newbie Hql and Collection
PostPosted: Thu Aug 31, 2006 5:39 pm 
Newbie

Joined: Thu Aug 31, 2006 5:18 pm
Posts: 8
Excuse for my bad english
I have generated 2 object, this is the file mapping :

<class name="Vega.Data.Magazzini, VegaData" dynamic-update="true" table="TA_Magazzini">
<id name="IdMagazzino" column="Id_magazzino" unsaved-value="0">
<generator
class="native" />
</id>
<property name="IdAzienda" column="Id_azienda" />
<property name="Targa" column="Targa" />
<property name="Descrizione" column="descrizione" />
<bag name="MagazzinoList" access="property" table="TA_Magazzino" lazy="true" cascade="all-delete-orphan" inverse="true" outer-join ="false">
<key column="Id_magazzino" />
<one-to-many class="Vega.Data.Magazzino,VegaData" />
</bag>
</class>

the second object

<class name ="Vega.Data.Magazzino, VegaData" table ="TA_Magazzino" dynamic-update ="true">
<id name="IdArticolo" column="Id_articolo" unsaved-value ="0">
<generator class ="native" />
</id>
<property name ="CodArticolo" column ="cod_articolo"/>
<property name ="Descrizione" column ="descrizione"/>
<property name ="PrezzoAcq" column ="prezzo_acq" type="Decimal(10,2)" />
<property name ="PrezzoVendita" column ="prezzo_vendita" type="Decimal(10,2)" />
<property name ="Qta" column ="qta" type="Decimal(10,2)"/>
<property name ="Um" column ="Um"/>
<property name ="Visualizza" column ="visualizza" />
<many-to-one name="Magazzini" column ="Id_magazzino" update="true" insert="true" outer-join ="false"/>
</class>

My collection work correctly if i use
session.Get(GetType(Magazzini), 1), Magazzini), Nhibernate create one object Magazzini and 3 object Magazzino (child). OK

But if get the object with this hql query

session.CreateQuery("from Magazzini m left join fetch m.MagazzinoList L where m.IdMagazzino = :Id and (L.Visualizza=1)") Nhibernate duplicate the object Magazzini (3 in this case). Its possible get the parent object and filter the child collection with an HQL query ?
Thanks
Stefano Paparesta


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 01, 2006 2:25 am 
Senior
Senior

Joined: Mon Aug 21, 2006 9:18 am
Posts: 179
Try putting inverse="true" on this collection
<one-to-many class="Vega.Data.Magazzino,VegaData" />

like so..

<one-to-many class="Vega.Data.Magazzino,VegaData" inverse="true"/>

I blogged about a similar issue http://geekswithblogs.net/opiesblog/archive/2006/06/08/81205.aspx.

Hope this helps!
--MIKE

Please rate if this helped!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 01, 2006 4:35 am 
Newbie

Joined: Thu Aug 31, 2006 5:18 pm
Posts: 8
Thanks for the post, but in my <BAG> is presente
Code:
inverse="true"
.

Stefano


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 01, 2006 1:29 pm 
Senior
Senior

Joined: Mon Aug 21, 2006 9:18 am
Posts: 179
DOH! Sorry my fingers moved faster than my brain. I was addressing a common problem I cause for myslef.
The only thing I can see that would cause your duplication is the use of the left join in lieu of just an inner join.
good luck.

_________________
If this helped...please remember to rate it!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.