I've just tried to simplify my scenario to have a closer look to my main problem:
Now, I'm just loading A. No join anymore. And it still executes the additional queries. This seems to confirm my assumption, that it tries to load the referring many-to-one objects of A. It is noticeable that the amount of additional queries is the same as many-to-one references... :| There seems to be a link between these circumstances. Back to my basic question: Why does nhibernate loads my many-to-one associations although they are not needed? And can I prevent this? Sorry for asking all over again, but this really important. Maybe I'll have a closer look to the nhibernate sources? Thanks Fred F. On 18 Mrz., 15:37, Fabio Maulo <[email protected]> wrote: > Additional query happen when there is not a relation ?for example when B.C > is null. > > 2009/3/18 Fred F. <[email protected]> > > > > > > > > > Hi Fabio, > > > thanks for your reply. > > > > Remove all specification about "lazy" and "fetch" from your mappings.For > > who > > > are new in NH the best way is : > > > -write your mapping specifying less as possible; string length when is > > > different than 255, scale+precision for double, after that write only > > what > > > is required. > > > Ok, but well... I started with less as possible. Afterwards I added > > the different options for lazy loading. > > > > -study how work with eager loading trough HQL and/or CriteriaAPI > > > I think I did. I know, that I don't want to load in eager mode, as I > > don't need the additional loaded Informations. I'm using the > > CriteriaAPI. > > > > When your app is working: > > > Go to reference and study "Improving performance" > > > I think I did. I've learned a lot about fetching strategies and > > created the ideal sql statement via the criteriaAPI. But I can't find > > anything about my basic problem: > > Why is it fetching some data from the many-to-one references directly > > after executing my 'ideal' statement? Is this standard behaviour? Can > > I prevent him loading the other data, as I don't need this data right > > now? > > > > Take a look to this mapping > > > > <class name="OrdenDeCompra"> > > > <id name="Id"> > > > <generator class="hilo"/> > > > </id> > > > <many-to-one name="EmpresaCompra"/> > > > <many-to-one name="OrganizacionCompra"/> > > > <property name="Comentarios"/> > > > > <property name="Numero" length="35"/> > > > <property name="Nombre" length="50"/> > > > <property name="Usuario" length="30"/> > > > <property name="FechaCreacion"/> > > > <property name="FechaEnvio"/> > > > <property name="FechaPublicacion"/> > > > <property name="Estado"/> > > > <many-to-one name="Moneda"/> > > > <many-to-one name="MetodoDespacho"/> > > > <many-to-one name="FormaPago"/> > > > <many-to-one name="RazonSocial"/> > > > <many-to-one name="EmpresaVenta"/> > > > <many-to-one name="OrganizacionVenta"/> > > > <list name="Lineas" access="field.camelcase" cascade="all" > > inverse="true"> > > > <key column="IDOC" on-delete="cascade"/> > > > <list-index column="NUMLINEAOC"/> > > > <one-to-many class="OrdenDeCompraLinea"/> > > > </list> > > > </class> > > > Thanks for your help. > > > I've got something like this > > > [...] > > <many-to-one name="ext" class="MyAssembly.Ext, MyAssembly"> > > <column name="person" /> > > <column name="type" /> > > </many-to-one> > > [...] > > > > heavy to write no ? ;) > > > Obviously not. But I still don't understand why nhibernate does > > something like this: > > > <EditedLogfile> > > > 2009-03-18 14:44:19,664 [11] INFO NHibernate.Loader.Loader - SELECT > > [...] FROM myDB.workertype this_ > > left outer join myDB.contract contract2_ on this_.ID=contract2_.BV and > > this_.CLASS=contract2_.BVTYP > > left outer join myDB.company company3_ on > > contract2_.PARTNER=company3_.ID and > > contract2_.PARTNERTYP=company3_.CLASS > > inner join myDB.Department dep1_ on this_.ID=dep1_.BV and > > this_.CLASS=dep1_.BVTYP > > WHERE ( this_.CLASSID='external') AND LOWER(name) LIKE '%smith%' and > > department = 42 > > > <pause> > > This would be enough. This statement is perfectly alright. But the > > workertype-class has got some other many-to-one associations and loads > > them like the following... for each record of my query above! :( > > </pause> > > > 2009-03-18 14:44:21,410 [11] INFO NHibernate.Loader.Loader - SELECT > > [...] FROM myDB.workertype work0_ WHERE work0_.ID=:p0 and > > work0_.CLASS=:p1 > > > 2009-03-18 14:44:26,023 [11] INFO NHibernate.Loader.Loader - SELECT > > [...] FROM myDB.Person p0_ > > left outer join myDB.Image img1_ on p0_.ID=img1_.ID and > > p0_.CLASS=img1_.CLASS > > left outer join myDB.Person person2_ on img1_.ID=person2_.ID and > > img1_.CLASS=person2_.CLASS > > WHERE p0_.ID=:p0 and p0.CLASS=:p1 and ( p0_.CLASSID='worker') > > > 2009-03-18 14:44:26,070 [11] INFO NHibernate.Loader.Loader - SELECT > > [...] FROM myDB.Person worker0_ > > left outer join myDB.Image img1_ on worker0_.ID=img1_.ID and > > worker0_.CLASS=img1_.CLASS > > left outer join myDB.Person person2_ on img1_.ID=person2_.ID and > > img1_.CLASS=person2_.CLASS > > WHERE worker_.ID=:p0 and worker0_.CLASS=:p1 and > > ( worker0_.CLASSID='worker') > > > 2009-03-18 14:44:26,662 [11] INFO NHibernate.Loader.Loader - SELECT > > [..] FROM myDB.Person person0_ > > left outer join myDB.Image img1_ on person0_.ID=img1_.ID and > > person0_.CLASS=img1_.CLASS > > left outer join myDB.Person person2_ on img1_.ID=person2_.ID and > > img1_.CLASS=person2_.CLASS > > WHERE person0_.ID=:p0 and person0_.CLASS=:p1 > > > 2009-03-18 14:44:27,426 [11] INFO NHibernate.Loader.Loader - SELECT > > [...] FROM myDB.Person ext0_ > > left outer join myDB.Image img1_ on ext0_.ID=img1_.ID and > > ext0_.CLASS=img1_.CLASS > > left outer join myDB.Person person2_ on img1_.ID=person2_.ID and > > img1_.CLASS=person2_.CLASS > > WHERE ext0_.ID=:p0 and ext0_.CLASS=:p1 and > > ( ext0_.CLASSID='external') > > > </EditedLogfile> > > > Thanks in advance. Still looking for explanations. > > > > 2009/3/18 Fred F. <[email protected]> > > > > > Hi folks! > > > > > I'm using NHibernate v2.0.50727 and I'm quite uncertain about many-to- > > > > one and lazy loading, although I've read several blogs about this > > > > topic. > > > > > I've got following scenario: > > > > > Class A has a one-to-many relation to class B (bag collection) and B > > > > has got a many-to-one relation to class C. Class A an B do have some > > > > other many-to-one relations to other classes (lets say Relation R1 and > > > > Relation R2) which are not important for my query. > > > > > Class A (1)--->(n) Class B (n) ---> (1) Class C > > > > > Default is lazy=true, but I'm creating my criteria with an left outer > > > > join to the classes, so I only need one query for this case. I can see > > > > the correct query in my logs. This query returns a collection of > > > > records. I can test this query in my sql-client and everything is > > > > fine. So far so good. > > > > > But: > > > > > For _each_ of my records nhibernate sends additional queries to the > > > > database. And it seems that it queries for the related objects which > > > > are related to class A and B by many-to-one relations (Relation R1 and > > > > R2). This additional references are completely unnecessary in this > > > > case and they are not used in this part of the application. > > > > > My question: > > > > > Why is nhibernate quering for these additional objects although nobody > > > > uses them? I've tried several different options in my many-to-one > > > > relations like > > > > > outer-join="false" > > > > lazy="proxy" (I suppose I'm not aware of the effect) > > > > fetch="select"/fetch="join" > > > > > I've added lazy="false" to all classes. > > > > > How can I prevent nhibernate to load these not needed objects? It has > > > > quite an impact on my performance level. > > > > > Thanks in advance! > > > > Fred F. > > > > -- > > > Fabio Maulo- Zitierten Text ausblenden - > > > > - Zitierten Text anzeigen - > > -- > Fabio Maulo- Zitierten Text ausblenden - > > - Zitierten Text anzeigen - --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "nhusers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/nhusers?hl=en -~----------~----~----~----~------~----~------~--~---
