[fluent-nhib] Re: Need some explanations about LazyLoad method
Thanks James. That should do what I need! J From: fluent-nhibernate@googlegroups.com [mailto:fluent-nhibern...@googlegroups.com] On Behalf Of James Gregory Sent: quinta-feira, 29 de Janeiro de 2009 22:35 To: fluent-nhibernate@googlegroups.com Subject: [fluent-nhib] Re: Need some explanations about LazyLoad method Luis: I've just committed a change that'll affect this. I've added LazyLoad to subclass, and I've updated everything to use a Not property instead of explicit NotXXX methods; that way we won't forget about doing a Not something in the future. So it's now: LazyLoad() and Not.LazyLoad(), these are available wherever LazyLoad was before, and also on the subclass. On Tue, Jan 27, 2009 at 12:43 PM, Luis Abreu lab...@gmail.com wrote: Yeah, and if i recall correctly, the default is lazy loading, which is not working for meJ Thanks again. From: fluent-nhibernate@googlegroups.com [mailto:fluent-nhibern...@googlegroups.com] On Behalf Of James Gregory Sent: terça-feira, 27 de Janeiro de 2009 12:36 To: fluent-nhibernate@googlegroups.com Subject: [fluent-nhib] Re: Need some explanations about LazyLoad method That sounds correct, although there should be a NotLazyLoaded method. By not setting any lazy load, FNH leaves the attribute off all together; this makes it fall back onto NHibernate's defaults. I shall add that method to my list of changes. On Tue, Jan 27, 2009 at 12:33 PM, Luis Abreu lab...@gmail.com wrote: Oh, just remembered…and what about the lazy attribute on the other properties (references)? For instance, on collections…I see there is a LazyLoad method but there isn't a NoLazyLoad method. So, I assumed that if I don't call that method I wouldn't get lazy loading and would get the lazy=false on the roperty mapping. This isn't happening. Any reason for that? Thanks again Luis From: fluent-nhibernate@googlegroups.com [mailto:fluent-nhibern...@googlegroups.com] On Behalf Of James Gregory Sent: terça-feira, 27 de Janeiro de 2009 12:26 To: fluent-nhibernate@googlegroups.com Subject: [fluent-nhib] Re: Need some explanations about LazyLoad method Excellent! Glad we got there in the end. On Tue, Jan 27, 2009 at 12:23 PM, Luis Abreu lab...@gmail.com wrote: James, thanks for your time! As always, the mistake was mine: the error were coming from the snapshot classes which also had inheritance. Thanks again. From: fluent-nhibernate@googlegroups.com [mailto:fluent-nhibern...@googlegroups.com] On Behalf Of James Gregory Sent: terça-feira, 27 de Janeiro de 2009 12:12 To: fluent-nhibernate@googlegroups.com Subject: [fluent-nhib] Re: Need some explanations about LazyLoad method That looks right to me, and you have NotLazyLoaded set on the main class too? In my setup I've got default-lazy to true, the parent class set to false, and all the subclasses also set to false. That works for me. On Tue, Jan 27, 2009 at 12:08 PM, Luis Abreu lab...@gmail.com wrote: I'm seeing the lazy=false on the XML but I'm still getting the same error if I don't set the default-lazy to false. Btw, here's the mapping of one of the subclasses: DiscriminateSubClassesOnColumn(TipoEntidade, (Int32) (EntityKind.Single)) .SubClassIndividual((Int32) (EntityKind.Single), e = { e.Map(ind = ind.BirthDate, DataNascimento); e.ComponentBIInfo(ind = ind.BIInfo, bi = { bi.Map(b = b.Archive, Arquivo) .WithLengthOf(100); bi.Map(b = b.EmissionDate, DataEmissao) .WithLengthOf(50); bi.Map(b = b.Number, BI) .WithLengthOf(20); }); e.SetAttribute( lazy, false ); }) .SubClassCompany((Int32)(EntityKind.Company), e = e.SetAttribute(lazy, false) ); See anything wrong? Thanks. From: fluent-nhibernate@googlegroups.com [mailto:fluent-nhibern...@googlegroups.com] On Behalf Of James Gregory Sent: terça-feira, 27 de Janeiro de 2009 11:49 To: fluent-nhibernate@googlegroups.com Subject: [fluent-nhib] Re: Need some explanations about LazyLoad method You didn't mention it was a subclass that was failing! Subclasses also have their own lazy attribute as well as their parent class, and I can now see we haven't mapped a way to handle this in FNH. You SHOULD do something like this (but can't right now): DiscriminateSubClassesOnColumn(TipoEntidade) .SubClassIndividual(subclass = { subclass.Map(...); subclass.NotLazyLoaded(); }); However, as you can't do that currently, you can use SetAttribute instead
[fluent-nhib] Re: Need some explanations about LazyLoad method
No, I'm not talking about relationships here.just a simple class. I had a working project with a previous version of fluent. At the time, it didn't set default-lazy. When I updated to a recent release, I started getting several errors on my test complaining about not having virtual properties. It was then that I've checked the generated xml and I saw that now fluent nh sets the default-lazy attribute to true. What I don't understand is why putting the lazy=false on the class element is not enough for cancelling lazing loading on a class. The only way I solved it was to access the Conventions property of the mapping visitor and put its defaultlazyload to false. Now, this probably is not a fluent issue (though it only surfaced due to its use on my project), but I've already asked on the NH forum and nobody answered it. Thanks, From: fluent-nhibernate@googlegroups.com [mailto:fluent-nhibern...@googlegroups.com] On Behalf Of James Gregory Sent: segunda-feira, 26 de Janeiro de 2009 18:46 To: fluent-nhibernate@googlegroups.com Subject: [fluent-nhib] Re: Need some explanations about LazyLoad method What relationship are you talking about Luis? One-to-many? Many-to-many? Many-to-one? On Mon, Jan 26, 2009 at 6:35 PM, Luis Abreu lab...@gmail.com wrote: Guys, pause please! Ok, I can see that adding the notlazyloaded method call will put lazy = false on my class on the generated xml. Now the problem is that when this xml is loaded I get exceptions saying that my properties aren't virtual (and no, they're not and no I don't want lazy lozading on myt class). Can anyone help and tell me why NH insist in using lazy when the lazy attribute on the class is set to false and the default-lazy attribute on the nhibernate element is set to true? Thanks. -Original Message- From: fluent-nhibernate@googlegroups.com [mailto:fluent- nhibern...@googlegroups.com] On Behalf Of VisualHint Sent: segunda-feira, 26 de Janeiro de 2009 15:58 To: Fluent NHibernate Subject: [fluent-nhib] Re: Need some explanations about LazyLoad method I understand a bit better now but note that: 1. When I generate the hbm from FNH and both LazyLoad and NotLazyLoaded are not set on the class, then no lazy attribute is added to the hbm file which maybe contradicts what you say (Fluent NHibernate always sets something) 2. If your explanation is right, LazyLoad() on the association is absolutely of no use. N. On Jan 26, 10:23 am, James Gregory jagregory@gmail.com wrote: That sounds correct to me. Whatever gets set on the class takes precedence over what you set in the relationship. HBM allowed you to not set anything for lazy load, while Fluent NHibernate always sets something; there's no way not to specify a value. So the lazy on the relationship is used when the entity doesn't have any kind of lazy setting, but if it does then it overrides whatever is set on the relationship; because FNH always sets a lazy value, it always overrides the relationship. No bug here as far as I can tell, but the lazy on the references method is perhaps redundant. On Mon, Jan 26, 2009 at 3:16 PM, VisualHint cadil...@gmail.com wrote: ok, so now that the default is lazy=true, I added NotLazyLoaded to my classmap. I set LazyLoad on my association only and again it is not lazy loaded. If however, I remove NotLazyLoaded, then the default takes precedence and with or without LazyLoad on my association, it is lazy loaded. So I suspect something is wrong in the first case. The fault to NH maybe (I'm with 2.1.0.1001). N. On Jan 26, 10:09 am, James Gregory jagregory@gmail.com wrote: How are you getting your fluent mappings into nhibernate? default-lazy should definitely be true if you're running on the latest trunk. On Mon, Jan 26, 2009 at 2:54 PM, VisualHint cadil...@gmail.com wrote: If I call System.Xml.XmlDocument doc = CreateMapping(new FluentNHibernate.MappingVisitor()); I get an hbm that has default-lazy=false and I can assure you that I got the latest FNH from the trunk, rebuilt it and referenced it. The various lazy settings are correctly added in the xml file for the 2 versions of LazyLoad() methods. I don't touch to the conventions. Configuration is done through the hibernate.cfg.xml and it contains only the minimum: ?xml version=1.0 encoding=utf-8 ? hibernate-configuration xmlns=urn:nhibernate-configuration- 2.2 session-factory property name=connection.connection_stringServer=. \SQLEXPRESS;Database=mydb;Integrated Security=True;/property property name=dialectNHibernate.Dialect.MsSql2005Dialect/ property property name=connection.providerNHibernate.Connection.DriverConnectionProvid er/ property property name=connection.driver_classNHibernate.Driver.SqlClientDriver/ property property name
[fluent-nhib] Re: Need some explanations about LazyLoad method
Hello again. You're not going to like this answer... it works for me! Yep, I don't like that answer :) Ok, back to my code. First, I'm not using sessionsource because the assembly is not signed and since it has dependencies on non-signed assemblies I cannot sign it here. So, I'm just getting the XML from the mappings by using code similar to this: var currentTypes = GetType().Assembly.GetTypes(); var methodsThatReturnXmlDocs = currentTypes .Where(existingType = GetMethodForExecution(existingType) != null) .Select(existingType = GetMethodForExecution(existingType)) .ToList(); foreach (var method in methodsThatReturnXmlDocs) { var mappingVisitor = new MappingVisitor(); mappingVisitor.Conventions.DefaultLazyLoad = false; //HAD TO ADD THIS var doc = method(mappingVisitor); configuration.AddDocument(doc); } Ok, here's the XML my mappings are generating: ?xml version=1.0 encoding=utf-8? hibernate-mapping xmlns=urn:nhibernate-mapping-2.2 default-lazy=false assembly=Sra.Core.Entities namespace=Sra.Core.Entities class name=Entity table=Entidades xmlns=urn:nhibernate-mapping-2.2 lazy=false discriminator-value=0 id name=Id column=IdEntidade type=Int32 unsaved-value=0 generator class=identity / /id discriminator column=TipoEntidade type=Int32 / version column=Version name=Version / property name=Name column=Nome length=200 type=String not-null=true column name=Nome / /property property name=Nif column=NIF length=9 type=String not-null=true column name=NIF / /property property name=Nifap column=Nifap length=50 type=String not-null=true column name=Nifap / /property many-to-one cascade=save-update name=Action column=IdAccao / set name=Branches access=field.camelcase-underscore cascade=all key column=IdEntidade / one-to-many class=Sra.Core.Entities.Branch, Sra.Core.Entities, Version=1.0.0.0, Culture=neutral, PublicKeyToken=7559314325872dac / /set subclass name=Sra.Core.Entities.Company, Sra.Core.Entities, Version=1.0.0.0, Culture=neutral, PublicKeyToken=7559314325872dac discriminator-value=1 / subclass name=Sra.Core.Entities.Individual, Sra.Core.Entities, Version=1.0.0.0, Culture=neutral, PublicKeyToken=7559314325872dac discriminator-value=0 property name=BirthDate column=DataNascimento column name=DataNascimento / /property component name=BIInfo insert=true update=true property name=Number column=BI length=20 type=String column name=BI / /property property name=EmissionDate column=DataEmissao length=50 type=String column name=DataEmissao / /property property name=Archive column=Arquivo length=100 type=String column name=Arquivo / /property /component /subclass /class /hibernate-mapping Now here's the XML when I don't set the default lazy convention (which means it's set to true by default, right?): hibernate-mapping xmlns=urn:nhibernate-mapping-2.2 default-lazy=true assembly=Sra.Core.Entities namespace=Sra.Core.Entities class name=Entity table=Entidades xmlns=urn:nhibernate-mapping-2.2 lazy=false discriminator-value=0 id name=Id column=IdEntidade type=Int32 unsaved-value=0 generator class=identity / /id discriminator column=TipoEntidade type=Int32 / version column=Version name=Version / property name=Name column=Nome length=200 type=String not-null=true column name=Nome / /property property name=Nif column=NIF length=9 type=String not-null=true column name=NIF / /property property name=Nifap column=Nifap length=50 type=String not-null=true column name=Nifap / /property many-to-one cascade=save-update name=Action column=IdAccao / set name=Branches access=field.camelcase-underscore cascade=all key column=IdEntidade / one-to-many class=Sra.Core.Entities.Branch, Sra.Core.Entities, Version=1.0.0.0, Culture=neutral, PublicKeyToken=7559314325872dac / /set subclass name=Sra.Core.Entities.Company, Sra.Core.Entities, Version=1.0.0.0, Culture=neutral, PublicKeyToken=7559314325872dac discriminator-value=1 / subclass name=Sra.Core.Entities.Individual, Sra.Core.Entities, Version=1.0.0.0, Culture=neutral, PublicKeyToken=7559314325872dac discriminator-value=0 property name=BirthDate column=DataNascimento column name=DataNascimento / /property component name=BIInfo insert=true update=true property name=Number column=BI length=20 type=String column name=BI / /property property name=EmissionDate column=DataEmissao length=50 type=String column name=DataEmissao / /property property name=Archive column=Arquivo length=100 type=String column name=Arquivo / /property /component /subclass /class /hibernate-mapping And in here's the exception I'm
[fluent-nhib] Re: Need some explanations about LazyLoad method
That looks right to me, and you have NotLazyLoaded set on the main class too? In my setup I've got default-lazy to true, the parent class set to false, and all the subclasses also set to false. That works for me. On Tue, Jan 27, 2009 at 12:08 PM, Luis Abreu lab...@gmail.com wrote: I'm seeing the lazy=false on the XML but I'm still getting the same error if I don't set the default-lazy to false. Btw, here's the mapping of one of the subclasses: DiscriminateSubClassesOnColumn(TipoEntidade, (Int32) (EntityKind.Single)) .SubClassIndividual((Int32) (EntityKind.Single), e = { e.Map(ind = ind.BirthDate, DataNascimento); e.ComponentBIInfo(ind = ind.BIInfo, bi = { bi.Map(b = b.Archive, Arquivo) .WithLengthOf(100); bi.Map(b = b.EmissionDate, DataEmissao) .WithLengthOf(50); bi.Map(b = b.Number, BI) .WithLengthOf(20); }); e.SetAttribute( lazy, false ); }) .SubClassCompany((Int32)(EntityKind.Company), e = e.SetAttribute(lazy, false) ); See anything wrong? Thanks. *From:* fluent-nhibernate@googlegroups.com [mailto: fluent-nhibern...@googlegroups.com] *On Behalf Of *James Gregory *Sent:* terça-feira, 27 de Janeiro de 2009 11:49 *To:* fluent-nhibernate@googlegroups.com *Subject:* [fluent-nhib] Re: Need some explanations about LazyLoad method You didn't mention it was a subclass that was failing! Subclasses also have their own lazy attribute as well as their parent class, and I can now see we haven't mapped a way to handle this in FNH. You SHOULD do something like this (but can't right now): DiscriminateSubClassesOnColumn(TipoEntidade) .SubClassIndividual(subclass = { subclass.Map(...); *subclass.NotLazyLoaded();* }); However, as you can't do that currently, you can use SetAttribute instead. subclass.SetAttribute(lazy, false); I'll look into getting this implemented properly. Let me know if the set attribute hack works. On Tue, Jan 27, 2009 at 11:36 AM, Luis Abreu lab...@gmail.com wrote: Hello again. You're not going to like this answer... it works for me! Yep, I don't like that answer :) Ok, back to my code. First, I'm not using sessionsource because the assembly is not signed and since it has dependencies on non-signed assemblies I cannot sign it here. So, I'm just getting the XML from the mappings by using code similar to this: var currentTypes = GetType().Assembly.GetTypes(); var methodsThatReturnXmlDocs = currentTypes .Where(existingType = GetMethodForExecution(existingType) != null) .Select(existingType = GetMethodForExecution(existingType)) .ToList(); foreach (var method in methodsThatReturnXmlDocs) { var mappingVisitor = new MappingVisitor(); mappingVisitor.Conventions.DefaultLazyLoad = false; //HAD TO ADD THIS var doc = method(mappingVisitor); configuration.AddDocument(doc); } Ok, here's the XML my mappings are generating: ?xml version=1.0 encoding=utf-8? hibernate-mapping xmlns=urn:nhibernate-mapping-2.2 default-lazy=false assembly=Sra.Core.Entities namespace=Sra.Core.Entities class name=Entity table=Entidades xmlns=urn:nhibernate-mapping-2.2 lazy=false discriminator-value=0 id name=Id column=IdEntidade type=Int32 unsaved-value=0 generator class=identity / /id discriminator column=TipoEntidade type=Int32 / version column=Version name=Version / property name=Name column=Nome length=200 type=String not-null=true column name=Nome / /property property name=Nif column=NIF length=9 type=String not-null=true column name=NIF / /property property name=Nifap column=Nifap length=50 type=String not-null=true column name=Nifap / /property many-to-one cascade=save-update name=Action column=IdAccao / set name=Branches access=field.camelcase-underscore cascade=all key column=IdEntidade / one-to-many class=Sra.Core.Entities.Branch, Sra.Core.Entities, Version=1.0.0.0, Culture=neutral, PublicKeyToken=7559314325872dac / /set subclass name=Sra.Core.Entities.Company, Sra.Core.Entities, Version=1.0.0.0, Culture=neutral, PublicKeyToken=7559314325872dac discriminator-value=1 / subclass name=Sra.Core.Entities.Individual, Sra.Core.Entities, Version=1.0.0.0, Culture=neutral, PublicKeyToken=7559314325872dac discriminator-value=0 property name=BirthDate column=DataNascimento column name
[fluent-nhib] Re: Need some explanations about LazyLoad method
Excellent! Glad we got there in the end. On Tue, Jan 27, 2009 at 12:23 PM, Luis Abreu lab...@gmail.com wrote: James, thanks for your time! As always, the mistake was mine: the error were coming from the snapshot classes which also had inheritance. Thanks again. *From:* fluent-nhibernate@googlegroups.com [mailto: fluent-nhibern...@googlegroups.com] *On Behalf Of *James Gregory *Sent:* terça-feira, 27 de Janeiro de 2009 12:12 *To:* fluent-nhibernate@googlegroups.com *Subject:* [fluent-nhib] Re: Need some explanations about LazyLoad method That looks right to me, and you have NotLazyLoaded set on the main class too? In my setup I've got default-lazy to true, the parent class set to false, and all the subclasses also set to false. That works for me. On Tue, Jan 27, 2009 at 12:08 PM, Luis Abreu lab...@gmail.com wrote: I'm seeing the lazy=false on the XML but I'm still getting the same error if I don't set the default-lazy to false. Btw, here's the mapping of one of the subclasses: DiscriminateSubClassesOnColumn(TipoEntidade, (Int32) (EntityKind.Single)) .SubClassIndividual((Int32) (EntityKind.Single), e = { e.Map(ind = ind.BirthDate, DataNascimento); e.ComponentBIInfo(ind = ind.BIInfo, bi = { bi.Map(b = b.Archive, Arquivo) .WithLengthOf(100); bi.Map(b = b.EmissionDate, DataEmissao) .WithLengthOf(50); bi.Map(b = b.Number, BI) .WithLengthOf(20); }); e.SetAttribute( lazy, false ); }) .SubClassCompany((Int32)(EntityKind.Company), e = e.SetAttribute(lazy, false) ); See anything wrong? Thanks. *From:* fluent-nhibernate@googlegroups.com [mailto: fluent-nhibern...@googlegroups.com] *On Behalf Of *James Gregory *Sent:* terça-feira, 27 de Janeiro de 2009 11:49 *To:* fluent-nhibernate@googlegroups.com *Subject:* [fluent-nhib] Re: Need some explanations about LazyLoad method You didn't mention it was a subclass that was failing! Subclasses also have their own lazy attribute as well as their parent class, and I can now see we haven't mapped a way to handle this in FNH. You SHOULD do something like this (but can't right now): DiscriminateSubClassesOnColumn(TipoEntidade) .SubClassIndividual(subclass = { subclass.Map(...); *subclass.NotLazyLoaded();* }); However, as you can't do that currently, you can use SetAttribute instead. subclass.SetAttribute(lazy, false); I'll look into getting this implemented properly. Let me know if the set attribute hack works. On Tue, Jan 27, 2009 at 11:36 AM, Luis Abreu lab...@gmail.com wrote: Hello again. You're not going to like this answer... it works for me! Yep, I don't like that answer :) Ok, back to my code. First, I'm not using sessionsource because the assembly is not signed and since it has dependencies on non-signed assemblies I cannot sign it here. So, I'm just getting the XML from the mappings by using code similar to this: var currentTypes = GetType().Assembly.GetTypes(); var methodsThatReturnXmlDocs = currentTypes .Where(existingType = GetMethodForExecution(existingType) != null) .Select(existingType = GetMethodForExecution(existingType)) .ToList(); foreach (var method in methodsThatReturnXmlDocs) { var mappingVisitor = new MappingVisitor(); mappingVisitor.Conventions.DefaultLazyLoad = false; //HAD TO ADD THIS var doc = method(mappingVisitor); configuration.AddDocument(doc); } Ok, here's the XML my mappings are generating: ?xml version=1.0 encoding=utf-8? hibernate-mapping xmlns=urn:nhibernate-mapping-2.2 default-lazy=false assembly=Sra.Core.Entities namespace=Sra.Core.Entities class name=Entity table=Entidades xmlns=urn:nhibernate-mapping-2.2 lazy=false discriminator-value=0 id name=Id column=IdEntidade type=Int32 unsaved-value=0 generator class=identity / /id discriminator column=TipoEntidade type=Int32 / version column=Version name=Version / property name=Name column=Nome length=200 type=String not-null=true column name=Nome / /property property name=Nif column=NIF length=9 type=String not-null=true column name=NIF / /property property name=Nifap column=Nifap length=50 type=String not-null=true column name=Nifap / /property many-to-one cascade=save-update name=Action column=IdAccao / set name=Branches access=field.camelcase
[fluent-nhib] Re: Need some explanations about LazyLoad method
That sounds correct, although there should be a NotLazyLoaded method. By not setting any lazy load, FNH leaves the attribute off all together; this makes it fall back onto NHibernate's defaults. I shall add that method to my list of changes. On Tue, Jan 27, 2009 at 12:33 PM, Luis Abreu lab...@gmail.com wrote: Oh, just remembered…and what about the lazy attribute on the other properties (references)? For instance, on collections…I see there is a LazyLoad method but there isn't a NoLazyLoad method. So, I assumed that if I don't call that method I wouldn't get lazy loading and would get the lazy=false on the roperty mapping. This isn't happening. Any reason for that? Thanks again Luis *From:* fluent-nhibernate@googlegroups.com [mailto: fluent-nhibern...@googlegroups.com] *On Behalf Of *James Gregory *Sent:* terça-feira, 27 de Janeiro de 2009 12:26 *To:* fluent-nhibernate@googlegroups.com *Subject:* [fluent-nhib] Re: Need some explanations about LazyLoad method Excellent! Glad we got there in the end. On Tue, Jan 27, 2009 at 12:23 PM, Luis Abreu lab...@gmail.com wrote: James, thanks for your time! As always, the mistake was mine: the error were coming from the snapshot classes which also had inheritance. Thanks again. *From:* fluent-nhibernate@googlegroups.com [mailto: fluent-nhibern...@googlegroups.com] *On Behalf Of *James Gregory *Sent:* terça-feira, 27 de Janeiro de 2009 12:12 *To:* fluent-nhibernate@googlegroups.com *Subject:* [fluent-nhib] Re: Need some explanations about LazyLoad method That looks right to me, and you have NotLazyLoaded set on the main class too? In my setup I've got default-lazy to true, the parent class set to false, and all the subclasses also set to false. That works for me. On Tue, Jan 27, 2009 at 12:08 PM, Luis Abreu lab...@gmail.com wrote: I'm seeing the lazy=false on the XML but I'm still getting the same error if I don't set the default-lazy to false. Btw, here's the mapping of one of the subclasses: DiscriminateSubClassesOnColumn(TipoEntidade, (Int32) (EntityKind.Single)) .SubClassIndividual((Int32) (EntityKind.Single), e = { e.Map(ind = ind.BirthDate, DataNascimento); e.ComponentBIInfo(ind = ind.BIInfo, bi = { bi.Map(b = b.Archive, Arquivo) .WithLengthOf(100); bi.Map(b = b.EmissionDate, DataEmissao) .WithLengthOf(50); bi.Map(b = b.Number, BI) .WithLengthOf(20); }); e.SetAttribute( lazy, false ); }) .SubClassCompany((Int32)(EntityKind.Company), e = e.SetAttribute(lazy, false) ); See anything wrong? Thanks. *From:* fluent-nhibernate@googlegroups.com [mailto: fluent-nhibern...@googlegroups.com] *On Behalf Of *James Gregory *Sent:* terça-feira, 27 de Janeiro de 2009 11:49 *To:* fluent-nhibernate@googlegroups.com *Subject:* [fluent-nhib] Re: Need some explanations about LazyLoad method You didn't mention it was a subclass that was failing! Subclasses also have their own lazy attribute as well as their parent class, and I can now see we haven't mapped a way to handle this in FNH. You SHOULD do something like this (but can't right now): DiscriminateSubClassesOnColumn(TipoEntidade) .SubClassIndividual(subclass = { subclass.Map(...); *subclass.NotLazyLoaded();* }); However, as you can't do that currently, you can use SetAttribute instead. subclass.SetAttribute(lazy, false); I'll look into getting this implemented properly. Let me know if the set attribute hack works. On Tue, Jan 27, 2009 at 11:36 AM, Luis Abreu lab...@gmail.com wrote: Hello again. You're not going to like this answer... it works for me! Yep, I don't like that answer :) Ok, back to my code. First, I'm not using sessionsource because the assembly is not signed and since it has dependencies on non-signed assemblies I cannot sign it here. So, I'm just getting the XML from the mappings by using code similar to this: var currentTypes = GetType().Assembly.GetTypes(); var methodsThatReturnXmlDocs = currentTypes .Where(existingType = GetMethodForExecution(existingType) != null) .Select(existingType = GetMethodForExecution(existingType)) .ToList(); foreach (var method in methodsThatReturnXmlDocs) { var mappingVisitor = new MappingVisitor(); mappingVisitor.Conventions.DefaultLazyLoad = false; //HAD TO ADD THIS var doc = method(mappingVisitor
[fluent-nhib] Re: Need some explanations about LazyLoad method
If I call System.Xml.XmlDocument doc = CreateMapping(new FluentNHibernate.MappingVisitor()); I get an hbm that has default-lazy=false and I can assure you that I got the latest FNH from the trunk, rebuilt it and referenced it. The various lazy settings are correctly added in the xml file for the 2 versions of LazyLoad() methods. I don't touch to the conventions. Configuration is done through the hibernate.cfg.xml and it contains only the minimum: ?xml version=1.0 encoding=utf-8 ? hibernate-configuration xmlns=urn:nhibernate-configuration-2.2 session-factory property name=connection.connection_stringServer=. \SQLEXPRESS;Database=mydb;Integrated Security=True;/property property name=dialectNHibernate.Dialect.MsSql2005Dialect/ property property name=connection.providerNHibernate.Connection.DriverConnectionProvider/ property property name=connection.driver_classNHibernate.Driver.SqlClientDriver/ property property name=connection.release_modeauto/property property name=adonet.batch_size500/property property name=show_sqltrue/property property name=generate_statisticstrue/property /session-factory /hibernate-configuration On Jan 26, 9:45 am, James Gregory jagregory@gmail.com wrote: By default the default-lazy attribute is set to true on every mapping created by Fluent NHibernate, so unless you've overridden this using the conventions, that's what's getting set. As far as I understand, this infers the class level setting. How are you configuring your session factory? Could you write out your mappings using the WriteMappingsTo method of the PersistenceModel, then we can see what's actually being generated. On Mon, Jan 26, 2009 at 1:58 PM, VisualHint cadil...@gmail.com wrote: I use the latest FNH and it still doesn't work. I have to explicitely set LazyLoad on the classmap to get this behavior. I understand the difference between the 2 lazyload methods but I don't understand when you say: however, the class gets precedence, so if your class isn't set to lazy load (which was the default) then the references call won't have any effect. Logically, if the entity is not forced to LazLoad then calling it or not on the association WOULD MAKE a difference. If you force it on the classmap then calling LazyLoad on the association would not change anything. If a NotLazyLoaded was possible on the association, then this one would make a difference. No? About trying with hbm, unfortunately, I tried to learn FNH before HBM so this is not something I can immediately try. N. On Jan 26, 7:14 am, James Gregory jagregory@gmail.com wrote: @Nicolas: How old is your copy of Fluent NHibernate? Originally it was the default that all entities would be not lazy loaded; so if your copy is from then, you won't see the lazy load behaviour. The two different lazy load methods you spoke of do different things, the lazy load on the class sets it at the entity level, so whenever that entity is referenced anywhere it's lazy loaded, the other sets it for that specific relationship; however, the class gets precedence, so if your class isn't set to lazy load (which was the default) then the references call won't have any effect. As Seb said, the reason the class lazy load requires virtual methods is because it creates a proxy of the entity. If your methods aren't already virtual, then your lazy loading won't be working because NHibernate won't know how to track it. So what do you need to do? Update your copy of FNH and try again, failing that, explicitly set lazy loading in your class and use virtuals; that's the recommended approach. Please note, this isn't a Fluent NHibernate specific issue, you'd be seeing the same behaviour for standard xml mapping too. On Mon, Jan 26, 2009 at 8:57 AM, Paul Batum paul.ba...@gmail.com wrote: When it comes to issues such as this I am somewhat of a broken record - my suggestion is always the same: See if you can get the desired behavior using HBM xml. Once you have working xml, we can compare it to what fluent nhibernate is generating and see where the problem lies. Paul Batum On Mon, Jan 26, 2009 at 9:16 AM, Chris Marisic ch...@marisic.com wrote: I noticed this also but I assumed I was handling the session incorrectly making it fully load the object but maybe this actually is an issue. On Jan 25, 9:20 am, VisualHint cadil...@gmail.com wrote: Yes I know that Seb (thx anyway). This was just telling a fact. My question is about LazyLoad and why it has no effect when called on a References() call. Nicolas On Jan 25, 3:44 am, Sebastien Lambla s...@serialseb.com wrote: But doing that has a consequence: All my properties in the one model must be virtual, even the ones that are not related to fields in my database. That's because the
[fluent-nhib] Re: Need some explanations about LazyLoad method
Btw, this is a problem I've faced in my mappings. Shouldn't the lazy attribute that you apply to a class element override that mapping? I'm asking this because I've had to change the default convention on my mappings so that I could discard the lazy loading options since it always insisted in using that when it read the xml generated by the mappers. From: fluent-nhibernate@googlegroups.com [mailto:fluent-nhibern...@googlegroups.com] On Behalf Of James Gregory Sent: segunda-feira, 26 de Janeiro de 2009 14:45 To: fluent-nhibernate@googlegroups.com Subject: [fluent-nhib] Re: Need some explanations about LazyLoad method By default the default-lazy attribute is set to true on every mapping created by Fluent NHibernate, so unless you've overridden this using the conventions, that's what's getting set. As far as I understand, this infers the class level setting. How are you configuring your session factory? Could you write out your mappings using the WriteMappingsTo method of the PersistenceModel, then we can see what's actually being generated. On Mon, Jan 26, 2009 at 1:58 PM, VisualHint cadil...@gmail.com wrote: I use the latest FNH and it still doesn't work. I have to explicitely set LazyLoad on the classmap to get this behavior. I understand the difference between the 2 lazyload methods but I don't understand when you say: however, the class gets precedence, so if your class isn't set to lazy load (which was the default) then the references call won't have any effect. Logically, if the entity is not forced to LazLoad then calling it or not on the association WOULD MAKE a difference. If you force it on the classmap then calling LazyLoad on the association would not change anything. If a NotLazyLoaded was possible on the association, then this one would make a difference. No? About trying with hbm, unfortunately, I tried to learn FNH before HBM so this is not something I can immediately try. N. On Jan 26, 7:14 am, James Gregory jagregory@gmail.com wrote: @Nicolas: How old is your copy of Fluent NHibernate? Originally it was the default that all entities would be not lazy loaded; so if your copy is from then, you won't see the lazy load behaviour. The two different lazy load methods you spoke of do different things, the lazy load on the class sets it at the entity level, so whenever that entity is referenced anywhere it's lazy loaded, the other sets it for that specific relationship; however, the class gets precedence, so if your class isn't set to lazy load (which was the default) then the references call won't have any effect. As Seb said, the reason the class lazy load requires virtual methods is because it creates a proxy of the entity. If your methods aren't already virtual, then your lazy loading won't be working because NHibernate won't know how to track it. So what do you need to do? Update your copy of FNH and try again, failing that, explicitly set lazy loading in your class and use virtuals; that's the recommended approach. Please note, this isn't a Fluent NHibernate specific issue, you'd be seeing the same behaviour for standard xml mapping too. On Mon, Jan 26, 2009 at 8:57 AM, Paul Batum paul.ba...@gmail.com wrote: When it comes to issues such as this I am somewhat of a broken record - my suggestion is always the same: See if you can get the desired behavior using HBM xml. Once you have working xml, we can compare it to what fluent nhibernate is generating and see where the problem lies. Paul Batum On Mon, Jan 26, 2009 at 9:16 AM, Chris Marisic ch...@marisic.com wrote: I noticed this also but I assumed I was handling the session incorrectly making it fully load the object but maybe this actually is an issue. On Jan 25, 9:20 am, VisualHint cadil...@gmail.com wrote: Yes I know that Seb (thx anyway). This was just telling a fact. My question is about LazyLoad and why it has no effect when called on a References() call. Nicolas On Jan 25, 3:44 am, Sebastien Lambla s...@serialseb.com wrote: But doing that has a consequence: All my properties in the one model must be virtual, even the ones that are not related to fields in my database. That's because the object is created as a proxy. Any of your property may have access or rely on other properties that need to be hydrated from the db. They all need to be virtual so that the first cal can trigger the load. This is an nhibernate thing. -- Seb _ Windows Live Messenger just got better .Video display pics, contact updates more.http://www.download.live.com/messenger --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Fluent NHibernate group. To post to this group, send email to fluent-nhibernate@googlegroups.com To unsubscribe from this group, send email to fluent
[fluent-nhib] Re: Need some explanations about LazyLoad method
How are you getting your fluent mappings into nhibernate? default-lazy should definitely be true if you're running on the latest trunk. On Mon, Jan 26, 2009 at 2:54 PM, VisualHint cadil...@gmail.com wrote: If I call System.Xml.XmlDocument doc = CreateMapping(new FluentNHibernate.MappingVisitor()); I get an hbm that has default-lazy=false and I can assure you that I got the latest FNH from the trunk, rebuilt it and referenced it. The various lazy settings are correctly added in the xml file for the 2 versions of LazyLoad() methods. I don't touch to the conventions. Configuration is done through the hibernate.cfg.xml and it contains only the minimum: ?xml version=1.0 encoding=utf-8 ? hibernate-configuration xmlns=urn:nhibernate-configuration-2.2 session-factory property name=connection.connection_stringServer=. \SQLEXPRESS;Database=mydb;Integrated Security=True;/property property name=dialectNHibernate.Dialect.MsSql2005Dialect/ property property name=connection.providerNHibernate.Connection.DriverConnectionProvider/ property property name=connection.driver_classNHibernate.Driver.SqlClientDriver/ property property name=connection.release_modeauto/property property name=adonet.batch_size500/property property name=show_sqltrue/property property name=generate_statisticstrue/property /session-factory /hibernate-configuration On Jan 26, 9:45 am, James Gregory jagregory@gmail.com wrote: By default the default-lazy attribute is set to true on every mapping created by Fluent NHibernate, so unless you've overridden this using the conventions, that's what's getting set. As far as I understand, this infers the class level setting. How are you configuring your session factory? Could you write out your mappings using the WriteMappingsTo method of the PersistenceModel, then we can see what's actually being generated. On Mon, Jan 26, 2009 at 1:58 PM, VisualHint cadil...@gmail.com wrote: I use the latest FNH and it still doesn't work. I have to explicitely set LazyLoad on the classmap to get this behavior. I understand the difference between the 2 lazyload methods but I don't understand when you say: however, the class gets precedence, so if your class isn't set to lazy load (which was the default) then the references call won't have any effect. Logically, if the entity is not forced to LazLoad then calling it or not on the association WOULD MAKE a difference. If you force it on the classmap then calling LazyLoad on the association would not change anything. If a NotLazyLoaded was possible on the association, then this one would make a difference. No? About trying with hbm, unfortunately, I tried to learn FNH before HBM so this is not something I can immediately try. N. On Jan 26, 7:14 am, James Gregory jagregory@gmail.com wrote: @Nicolas: How old is your copy of Fluent NHibernate? Originally it was the default that all entities would be not lazy loaded; so if your copy is from then, you won't see the lazy load behaviour. The two different lazy load methods you spoke of do different things, the lazy load on the class sets it at the entity level, so whenever that entity is referenced anywhere it's lazy loaded, the other sets it for that specific relationship; however, the class gets precedence, so if your class isn't set to lazy load (which was the default) then the references call won't have any effect. As Seb said, the reason the class lazy load requires virtual methods is because it creates a proxy of the entity. If your methods aren't already virtual, then your lazy loading won't be working because NHibernate won't know how to track it. So what do you need to do? Update your copy of FNH and try again, failing that, explicitly set lazy loading in your class and use virtuals; that's the recommended approach. Please note, this isn't a Fluent NHibernate specific issue, you'd be seeing the same behaviour for standard xml mapping too. On Mon, Jan 26, 2009 at 8:57 AM, Paul Batum paul.ba...@gmail.com wrote: When it comes to issues such as this I am somewhat of a broken record - my suggestion is always the same: See if you can get the desired behavior using HBM xml. Once you have working xml, we can compare it to what fluent nhibernate is generating and see where the problem lies. Paul Batum On Mon, Jan 26, 2009 at 9:16 AM, Chris Marisic ch...@marisic.com wrote: I noticed this also but I assumed I was handling the session incorrectly making it fully load the object but maybe this actually is an issue. On Jan 25, 9:20 am, VisualHint cadil...@gmail.com wrote: Yes I know that Seb (thx anyway). This was just telling a fact. My question is about LazyLoad and why it has no
[fluent-nhib] Re: Need some explanations about LazyLoad method
ok, so now that the default is lazy=true, I added NotLazyLoaded to my classmap. I set LazyLoad on my association only and again it is not lazy loaded. If however, I remove NotLazyLoaded, then the default takes precedence and with or without LazyLoad on my association, it is lazy loaded. So I suspect something is wrong in the first case. The fault to NH maybe (I'm with 2.1.0.1001). N. On Jan 26, 10:09 am, James Gregory jagregory@gmail.com wrote: How are you getting your fluent mappings into nhibernate? default-lazy should definitely be true if you're running on the latest trunk. On Mon, Jan 26, 2009 at 2:54 PM, VisualHint cadil...@gmail.com wrote: If I call System.Xml.XmlDocument doc = CreateMapping(new FluentNHibernate.MappingVisitor()); I get an hbm that has default-lazy=false and I can assure you that I got the latest FNH from the trunk, rebuilt it and referenced it. The various lazy settings are correctly added in the xml file for the 2 versions of LazyLoad() methods. I don't touch to the conventions. Configuration is done through the hibernate.cfg.xml and it contains only the minimum: ?xml version=1.0 encoding=utf-8 ? hibernate-configuration xmlns=urn:nhibernate-configuration-2.2 session-factory property name=connection.connection_stringServer=. \SQLEXPRESS;Database=mydb;Integrated Security=True;/property property name=dialectNHibernate.Dialect.MsSql2005Dialect/ property property name=connection.providerNHibernate.Connection.DriverConnectionProvider/ property property name=connection.driver_classNHibernate.Driver.SqlClientDriver/ property property name=connection.release_modeauto/property property name=adonet.batch_size500/property property name=show_sqltrue/property property name=generate_statisticstrue/property /session-factory /hibernate-configuration On Jan 26, 9:45 am, James Gregory jagregory@gmail.com wrote: By default the default-lazy attribute is set to true on every mapping created by Fluent NHibernate, so unless you've overridden this using the conventions, that's what's getting set. As far as I understand, this infers the class level setting. How are you configuring your session factory? Could you write out your mappings using the WriteMappingsTo method of the PersistenceModel, then we can see what's actually being generated. On Mon, Jan 26, 2009 at 1:58 PM, VisualHint cadil...@gmail.com wrote: I use the latest FNH and it still doesn't work. I have to explicitely set LazyLoad on the classmap to get this behavior. I understand the difference between the 2 lazyload methods but I don't understand when you say: however, the class gets precedence, so if your class isn't set to lazy load (which was the default) then the references call won't have any effect. Logically, if the entity is not forced to LazLoad then calling it or not on the association WOULD MAKE a difference. If you force it on the classmap then calling LazyLoad on the association would not change anything. If a NotLazyLoaded was possible on the association, then this one would make a difference. No? About trying with hbm, unfortunately, I tried to learn FNH before HBM so this is not something I can immediately try. N. On Jan 26, 7:14 am, James Gregory jagregory@gmail.com wrote: @Nicolas: How old is your copy of Fluent NHibernate? Originally it was the default that all entities would be not lazy loaded; so if your copy is from then, you won't see the lazy load behaviour. The two different lazy load methods you spoke of do different things, the lazy load on the class sets it at the entity level, so whenever that entity is referenced anywhere it's lazy loaded, the other sets it for that specific relationship; however, the class gets precedence, so if your class isn't set to lazy load (which was the default) then the references call won't have any effect. As Seb said, the reason the class lazy load requires virtual methods is because it creates a proxy of the entity. If your methods aren't already virtual, then your lazy loading won't be working because NHibernate won't know how to track it. So what do you need to do? Update your copy of FNH and try again, failing that, explicitly set lazy loading in your class and use virtuals; that's the recommended approach. Please note, this isn't a Fluent NHibernate specific issue, you'd be seeing the same behaviour for standard xml mapping too. On Mon, Jan 26, 2009 at 8:57 AM, Paul Batum paul.ba...@gmail.com wrote: When it comes to issues such as this I am somewhat of a broken record - my suggestion is always the same: See if you can get the desired behavior using HBM xml. Once you have working
[fluent-nhib] Re: Need some explanations about LazyLoad method
That sounds correct to me. Whatever gets set on the class takes precedence over what you set in the relationship. HBM allowed you to not set anything for lazy load, while Fluent NHibernate always sets something; there's no way not to specify a value. So the lazy on the relationship is used when the entity doesn't have any kind of lazy setting, but if it does then it overrides whatever is set on the relationship; because FNH always sets a lazy value, it always overrides the relationship. No bug here as far as I can tell, but the lazy on the references method is perhaps redundant. On Mon, Jan 26, 2009 at 3:16 PM, VisualHint cadil...@gmail.com wrote: ok, so now that the default is lazy=true, I added NotLazyLoaded to my classmap. I set LazyLoad on my association only and again it is not lazy loaded. If however, I remove NotLazyLoaded, then the default takes precedence and with or without LazyLoad on my association, it is lazy loaded. So I suspect something is wrong in the first case. The fault to NH maybe (I'm with 2.1.0.1001). N. On Jan 26, 10:09 am, James Gregory jagregory@gmail.com wrote: How are you getting your fluent mappings into nhibernate? default-lazy should definitely be true if you're running on the latest trunk. On Mon, Jan 26, 2009 at 2:54 PM, VisualHint cadil...@gmail.com wrote: If I call System.Xml.XmlDocument doc = CreateMapping(new FluentNHibernate.MappingVisitor()); I get an hbm that has default-lazy=false and I can assure you that I got the latest FNH from the trunk, rebuilt it and referenced it. The various lazy settings are correctly added in the xml file for the 2 versions of LazyLoad() methods. I don't touch to the conventions. Configuration is done through the hibernate.cfg.xml and it contains only the minimum: ?xml version=1.0 encoding=utf-8 ? hibernate-configuration xmlns=urn:nhibernate-configuration-2.2 session-factory property name=connection.connection_stringServer=. \SQLEXPRESS;Database=mydb;Integrated Security=True;/property property name=dialectNHibernate.Dialect.MsSql2005Dialect/ property property name=connection.providerNHibernate.Connection.DriverConnectionProvider/ property property name=connection.driver_classNHibernate.Driver.SqlClientDriver/ property property name=connection.release_modeauto/property property name=adonet.batch_size500/property property name=show_sqltrue/property property name=generate_statisticstrue/property /session-factory /hibernate-configuration On Jan 26, 9:45 am, James Gregory jagregory@gmail.com wrote: By default the default-lazy attribute is set to true on every mapping created by Fluent NHibernate, so unless you've overridden this using the conventions, that's what's getting set. As far as I understand, this infers the class level setting. How are you configuring your session factory? Could you write out your mappings using the WriteMappingsTo method of the PersistenceModel, then we can see what's actually being generated. On Mon, Jan 26, 2009 at 1:58 PM, VisualHint cadil...@gmail.com wrote: I use the latest FNH and it still doesn't work. I have to explicitely set LazyLoad on the classmap to get this behavior. I understand the difference between the 2 lazyload methods but I don't understand when you say: however, the class gets precedence, so if your class isn't set to lazy load (which was the default) then the references call won't have any effect. Logically, if the entity is not forced to LazLoad then calling it or not on the association WOULD MAKE a difference. If you force it on the classmap then calling LazyLoad on the association would not change anything. If a NotLazyLoaded was possible on the association, then this one would make a difference. No? About trying with hbm, unfortunately, I tried to learn FNH before HBM so this is not something I can immediately try. N. On Jan 26, 7:14 am, James Gregory jagregory@gmail.com wrote: @Nicolas: How old is your copy of Fluent NHibernate? Originally it was the default that all entities would be not lazy loaded; so if your copy is from then, you won't see the lazy load behaviour. The two different lazy load methods you spoke of do different things, the lazy load on the class sets it at the entity level, so whenever that entity is referenced anywhere it's lazy loaded, the other sets it for that specific relationship; however, the class gets precedence, so if your class isn't set to lazy load (which was the default) then the references call won't have any effect. As Seb said, the reason the class lazy load requires virtual methods is because it creates a proxy of the
[fluent-nhib] Re: Need some explanations about LazyLoad method
I understand a bit better now but note that: 1. When I generate the hbm from FNH and both LazyLoad and NotLazyLoaded are not set on the class, then no lazy attribute is added to the hbm file which maybe contradicts what you say (Fluent NHibernate always sets something) 2. If your explanation is right, LazyLoad() on the association is absolutely of no use. N. On Jan 26, 10:23 am, James Gregory jagregory@gmail.com wrote: That sounds correct to me. Whatever gets set on the class takes precedence over what you set in the relationship. HBM allowed you to not set anything for lazy load, while Fluent NHibernate always sets something; there's no way not to specify a value. So the lazy on the relationship is used when the entity doesn't have any kind of lazy setting, but if it does then it overrides whatever is set on the relationship; because FNH always sets a lazy value, it always overrides the relationship. No bug here as far as I can tell, but the lazy on the references method is perhaps redundant. On Mon, Jan 26, 2009 at 3:16 PM, VisualHint cadil...@gmail.com wrote: ok, so now that the default is lazy=true, I added NotLazyLoaded to my classmap. I set LazyLoad on my association only and again it is not lazy loaded. If however, I remove NotLazyLoaded, then the default takes precedence and with or without LazyLoad on my association, it is lazy loaded. So I suspect something is wrong in the first case. The fault to NH maybe (I'm with 2.1.0.1001). N. On Jan 26, 10:09 am, James Gregory jagregory@gmail.com wrote: How are you getting your fluent mappings into nhibernate? default-lazy should definitely be true if you're running on the latest trunk. On Mon, Jan 26, 2009 at 2:54 PM, VisualHint cadil...@gmail.com wrote: If I call System.Xml.XmlDocument doc = CreateMapping(new FluentNHibernate.MappingVisitor()); I get an hbm that has default-lazy=false and I can assure you that I got the latest FNH from the trunk, rebuilt it and referenced it. The various lazy settings are correctly added in the xml file for the 2 versions of LazyLoad() methods. I don't touch to the conventions. Configuration is done through the hibernate.cfg.xml and it contains only the minimum: ?xml version=1.0 encoding=utf-8 ? hibernate-configuration xmlns=urn:nhibernate-configuration-2.2 session-factory property name=connection.connection_stringServer=. \SQLEXPRESS;Database=mydb;Integrated Security=True;/property property name=dialectNHibernate.Dialect.MsSql2005Dialect/ property property name=connection.providerNHibernate.Connection.DriverConnectionProvider/ property property name=connection.driver_classNHibernate.Driver.SqlClientDriver/ property property name=connection.release_modeauto/property property name=adonet.batch_size500/property property name=show_sqltrue/property property name=generate_statisticstrue/property /session-factory /hibernate-configuration On Jan 26, 9:45 am, James Gregory jagregory@gmail.com wrote: By default the default-lazy attribute is set to true on every mapping created by Fluent NHibernate, so unless you've overridden this using the conventions, that's what's getting set. As far as I understand, this infers the class level setting. How are you configuring your session factory? Could you write out your mappings using the WriteMappingsTo method of the PersistenceModel, then we can see what's actually being generated. On Mon, Jan 26, 2009 at 1:58 PM, VisualHint cadil...@gmail.com wrote: I use the latest FNH and it still doesn't work. I have to explicitely set LazyLoad on the classmap to get this behavior. I understand the difference between the 2 lazyload methods but I don't understand when you say: however, the class gets precedence, so if your class isn't set to lazy load (which was the default) then the references call won't have any effect. Logically, if the entity is not forced to LazLoad then calling it or not on the association WOULD MAKE a difference. If you force it on the classmap then calling LazyLoad on the association would not change anything. If a NotLazyLoaded was possible on the association, then this one would make a difference. No? About trying with hbm, unfortunately, I tried to learn FNH before HBM so this is not something I can immediately try. N. On Jan 26, 7:14 am, James Gregory jagregory@gmail.com wrote: @Nicolas: How old is your copy of Fluent NHibernate? Originally it was the default that all entities would be not lazy loaded; so if your copy is from then, you won't see the lazy load behaviour. The two different lazy load methods you spoke of do different
[fluent-nhib] Re: Need some explanations about LazyLoad method
And anyway, my first issue persists. I was able to reset default-lazy to false by using conventions. I don't put LazyLoad() on my class map and set it to my association only. I used WriteMappingsTo wo check that no lazy attribute is defined on the class and lazy=proxy is defined on my association. With all that, my association is still eager loaded. So would it be a NH issue instead of a FNH one ? N. On Jan 26, 10:57 am, VisualHint cadil...@gmail.com wrote: I understand a bit better now but note that: 1. When I generate the hbm from FNH and both LazyLoad and NotLazyLoaded are not set on the class, then no lazy attribute is added to the hbm file which maybe contradicts what you say (Fluent NHibernate always sets something) 2. If your explanation is right, LazyLoad() on the association is absolutely of no use. N. On Jan 26, 10:23 am, James Gregory jagregory@gmail.com wrote: That sounds correct to me. Whatever gets set on the class takes precedence over what you set in the relationship. HBM allowed you to not set anything for lazy load, while Fluent NHibernate always sets something; there's no way not to specify a value. So the lazy on the relationship is used when the entity doesn't have any kind of lazy setting, but if it does then it overrides whatever is set on the relationship; because FNH always sets a lazy value, it always overrides the relationship. No bug here as far as I can tell, but the lazy on the references method is perhaps redundant. On Mon, Jan 26, 2009 at 3:16 PM, VisualHint cadil...@gmail.com wrote: ok, so now that the default is lazy=true, I added NotLazyLoaded to my classmap. I set LazyLoad on my association only and again it is not lazy loaded. If however, I remove NotLazyLoaded, then the default takes precedence and with or without LazyLoad on my association, it is lazy loaded. So I suspect something is wrong in the first case. The fault to NH maybe (I'm with 2.1.0.1001). N. On Jan 26, 10:09 am, James Gregory jagregory@gmail.com wrote: How are you getting your fluent mappings into nhibernate? default-lazy should definitely be true if you're running on the latest trunk. On Mon, Jan 26, 2009 at 2:54 PM, VisualHint cadil...@gmail.com wrote: If I call System.Xml.XmlDocument doc = CreateMapping(new FluentNHibernate.MappingVisitor()); I get an hbm that has default-lazy=false and I can assure you that I got the latest FNH from the trunk, rebuilt it and referenced it. The various lazy settings are correctly added in the xml file for the 2 versions of LazyLoad() methods. I don't touch to the conventions. Configuration is done through the hibernate.cfg.xml and it contains only the minimum: ?xml version=1.0 encoding=utf-8 ? hibernate-configuration xmlns=urn:nhibernate-configuration-2.2 session-factory property name=connection.connection_stringServer=. \SQLEXPRESS;Database=mydb;Integrated Security=True;/property property name=dialectNHibernate.Dialect.MsSql2005Dialect/ property property name=connection.providerNHibernate.Connection.DriverConnectionProvider/ property property name=connection.driver_classNHibernate.Driver.SqlClientDriver/ property property name=connection.release_modeauto/property property name=adonet.batch_size500/property property name=show_sqltrue/property property name=generate_statisticstrue/property /session-factory /hibernate-configuration On Jan 26, 9:45 am, James Gregory jagregory@gmail.com wrote: By default the default-lazy attribute is set to true on every mapping created by Fluent NHibernate, so unless you've overridden this using the conventions, that's what's getting set. As far as I understand, this infers the class level setting. How are you configuring your session factory? Could you write out your mappings using the WriteMappingsTo method of the PersistenceModel, then we can see what's actually being generated. On Mon, Jan 26, 2009 at 1:58 PM, VisualHint cadil...@gmail.com wrote: I use the latest FNH and it still doesn't work. I have to explicitely set LazyLoad on the classmap to get this behavior. I understand the difference between the 2 lazyload methods but I don't understand when you say: however, the class gets precedence, so if your class isn't set to lazy load (which was the default) then the references call won't have any effect. Logically, if the entity is not forced to LazLoad then calling it or not on the association WOULD MAKE a difference. If you force it on the classmap then calling LazyLoad on the association would not change anything. If a NotLazyLoaded was possible on the association, then
[fluent-nhib] Re: Need some explanations about LazyLoad method
Good point, I'll look into that. On Mon, Jan 26, 2009 at 6:09 PM, VisualHint cadil...@gmail.com wrote: Thanks for all James. I will just add that there is something missing in the FNH API. Since one have to set the class as LazyLoad to really get lazy loading working on an association, one also needs a way to invalidate the lazy loading on a single association, something like: References...().NotLazyLoaded() which would add the lazy=false on the association (I tried it manually with a SetAttribute and it works well). On Jan 26, 12:53 pm, James Gregory jagregory@gmail.com wrote: In this case yes, because References/many-to-one isn't a collection; NHibernate needs the properties to be virtual so it can create a proxy to detect when something tries to access the referenced object, at which point it can go fetch the actual data. On Mon, Jan 26, 2009 at 5:25 PM, android...@gmail.com wrote: So it's not possible to only lazy load associations/collections, the entire class has to be marked lazy load with every property set to virtual? On Jan 26, 12:07 pm, James Gregory jagregory@gmail.com wrote: I don't think this is an issue, you just have to set lazy on the class; that's just how it's done. If you don't set lazy on the class, NHibernate has no way of lazy loading it as it won't know how to create the proxy. On Mon, Jan 26, 2009 at 4:54 PM, VisualHint cadil...@gmail.com wrote: And anyway, my first issue persists. I was able to reset default-lazy to false by using conventions. I don't put LazyLoad() on my class map and set it to my association only. I used WriteMappingsTo wo check that no lazy attribute is defined on the class and lazy=proxy is defined on my association. With all that, my association is still eager loaded. So would it be a NH issue instead of a FNH one ? N. On Jan 26, 10:57 am, VisualHint cadil...@gmail.com wrote: I understand a bit better now but note that: 1. When I generate the hbm from FNH and both LazyLoad and NotLazyLoaded are not set on the class, then no lazy attribute is added to the hbm file which maybe contradicts what you say (Fluent NHibernate always sets something) 2. If your explanation is right, LazyLoad() on the association is absolutely of no use. N. On Jan 26, 10:23 am, James Gregory jagregory@gmail.com wrote: That sounds correct to me. Whatever gets set on the class takes precedence over what you set in the relationship. HBM allowed you to not set anything for lazy load, while Fluent NHibernate always sets something; there's no way not to specify a value. So the lazy on the relationship is used when the entity doesn't have any kind of lazy setting, but if it does then it overrides whatever is set on the relationship; because FNH always sets a lazy value, it always overrides the relationship. No bug here as far as I can tell, but the lazy on the references method is perhaps redundant. On Mon, Jan 26, 2009 at 3:16 PM, VisualHint cadil...@gmail.com wrote: ok, so now that the default is lazy=true, I added NotLazyLoaded to my classmap. I set LazyLoad on my association only and again it is not lazy loaded. If however, I remove NotLazyLoaded, then the default takes precedence and with or without LazyLoad on my association, it is lazy loaded. So I suspect something is wrong in the first case. The fault to NH maybe (I'm with 2.1.0.1001). N. On Jan 26, 10:09 am, James Gregory jagregory@gmail.com wrote: How are you getting your fluent mappings into nhibernate? default-lazy should definitely be true if you're running on the latest trunk. On Mon, Jan 26, 2009 at 2:54 PM, VisualHint cadil...@gmail.com wrote: If I call System.Xml.XmlDocument doc = CreateMapping(new FluentNHibernate.MappingVisitor()); I get an hbm that has default-lazy=false and I can assure you that I got the latest FNH from the trunk, rebuilt it and referenced it. The various lazy settings are correctly added in the xml file for the 2 versions of LazyLoad() methods. I don't touch to the conventions. Configuration is done through the hibernate.cfg.xml and it contains only the minimum: ?xml version=1.0 encoding=utf-8 ? hibernate-configuration xmlns=urn:nhibernate-configuration-2.2 session-factory property name=connection.connection_stringServer=. \SQLEXPRESS;Database=mydb;Integrated Security=True;/property property
[fluent-nhib] Re: Need some explanations about LazyLoad method
What relationship are you talking about Luis? One-to-many? Many-to-many? Many-to-one? On Mon, Jan 26, 2009 at 6:35 PM, Luis Abreu lab...@gmail.com wrote: Guys, pause please! Ok, I can see that adding the notlazyloaded method call will put lazy = false on my class on the generated xml. Now the problem is that when this xml is loaded I get exceptions saying that my properties aren't virtual (and no, they're not and no I don't want lazy lozading on myt class). Can anyone help and tell me why NH insist in using lazy when the lazy attribute on the class is set to false and the default-lazy attribute on the nhibernate element is set to true? Thanks. -Original Message- From: fluent-nhibernate@googlegroups.com [mailto:fluent- nhibern...@googlegroups.com] On Behalf Of VisualHint Sent: segunda-feira, 26 de Janeiro de 2009 15:58 To: Fluent NHibernate Subject: [fluent-nhib] Re: Need some explanations about LazyLoad method I understand a bit better now but note that: 1. When I generate the hbm from FNH and both LazyLoad and NotLazyLoaded are not set on the class, then no lazy attribute is added to the hbm file which maybe contradicts what you say (Fluent NHibernate always sets something) 2. If your explanation is right, LazyLoad() on the association is absolutely of no use. N. On Jan 26, 10:23 am, James Gregory jagregory@gmail.com wrote: That sounds correct to me. Whatever gets set on the class takes precedence over what you set in the relationship. HBM allowed you to not set anything for lazy load, while Fluent NHibernate always sets something; there's no way not to specify a value. So the lazy on the relationship is used when the entity doesn't have any kind of lazy setting, but if it does then it overrides whatever is set on the relationship; because FNH always sets a lazy value, it always overrides the relationship. No bug here as far as I can tell, but the lazy on the references method is perhaps redundant. On Mon, Jan 26, 2009 at 3:16 PM, VisualHint cadil...@gmail.com wrote: ok, so now that the default is lazy=true, I added NotLazyLoaded to my classmap. I set LazyLoad on my association only and again it is not lazy loaded. If however, I remove NotLazyLoaded, then the default takes precedence and with or without LazyLoad on my association, it is lazy loaded. So I suspect something is wrong in the first case. The fault to NH maybe (I'm with 2.1.0.1001). N. On Jan 26, 10:09 am, James Gregory jagregory@gmail.com wrote: How are you getting your fluent mappings into nhibernate? default-lazy should definitely be true if you're running on the latest trunk. On Mon, Jan 26, 2009 at 2:54 PM, VisualHint cadil...@gmail.com wrote: If I call System.Xml.XmlDocument doc = CreateMapping(new FluentNHibernate.MappingVisitor()); I get an hbm that has default-lazy=false and I can assure you that I got the latest FNH from the trunk, rebuilt it and referenced it. The various lazy settings are correctly added in the xml file for the 2 versions of LazyLoad() methods. I don't touch to the conventions. Configuration is done through the hibernate.cfg.xml and it contains only the minimum: ?xml version=1.0 encoding=utf-8 ? hibernate-configuration xmlns=urn:nhibernate-configuration- 2.2 session-factory property name=connection.connection_stringServer=. \SQLEXPRESS;Database=mydb;Integrated Security=True;/property property name=dialectNHibernate.Dialect.MsSql2005Dialect/ property property name=connection.providerNHibernate.Connection.DriverConnectionProvid er/ property property name=connection.driver_classNHibernate.Driver.SqlClientDriver/ property property name=connection.release_modeauto/property property name=adonet.batch_size500/property property name=show_sqltrue/property property name=generate_statisticstrue/property /session-factory /hibernate-configuration On Jan 26, 9:45 am, James Gregory jagregory@gmail.com wrote: By default the default-lazy attribute is set to true on every mapping created by Fluent NHibernate, so unless you've overridden this using the conventions, that's what's getting set. As far as I understand, this infers the class level setting. How are you configuring your session factory? Could you write out your mappings using the WriteMappingsTo method of the PersistenceModel, then we can see what's actually being generated. On Mon, Jan 26, 2009 at 1:58 PM, VisualHint cadil...@gmail.com wrote: I use the latest FNH and it still doesn't work. I have to explicitely set
[fluent-nhib] Re: Need some explanations about LazyLoad method
But doing that has a consequence: All my properties in the one model must be virtual, even the ones that are not related to fields in my database. That's because the object is created as a proxy. Any of your property may have access or rely on other properties that need to be hydrated from the db. They all need to be virtual so that the first cal can trigger the load. This is an nhibernate thing. -- Seb _ Windows Live Messenger just got better .Video display pics, contact updates more. http://www.download.live.com/messenger --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Fluent NHibernate group. To post to this group, send email to fluent-nhibernate@googlegroups.com To unsubscribe from this group, send email to fluent-nhibernate+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/fluent-nhibernate?hl=en -~--~~~~--~~--~--~---
[fluent-nhib] Re: Need some explanations about LazyLoad method
Yes I know that Seb (thx anyway). This was just telling a fact. My question is about LazyLoad and why it has no effect when called on a References() call. Nicolas On Jan 25, 3:44 am, Sebastien Lambla s...@serialseb.com wrote: But doing that has a consequence: All my properties in the one model must be virtual, even the ones that are not related to fields in my database. That's because the object is created as a proxy. Any of your property may have access or rely on other properties that need to be hydrated from the db. They all need to be virtual so that the first cal can trigger the load. This is an nhibernate thing. -- Seb _ Windows Live Messenger just got better .Video display pics, contact updates more.http://www.download.live.com/messenger --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Fluent NHibernate group. To post to this group, send email to fluent-nhibernate@googlegroups.com To unsubscribe from this group, send email to fluent-nhibernate+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/fluent-nhibernate?hl=en -~--~~~~--~~--~--~---
[fluent-nhib] Re: Need some explanations about LazyLoad method
I noticed this also but I assumed I was handling the session incorrectly making it fully load the object but maybe this actually is an issue. On Jan 25, 9:20 am, VisualHint cadil...@gmail.com wrote: Yes I know that Seb (thx anyway). This was just telling a fact. My question is about LazyLoad and why it has no effect when called on a References() call. Nicolas On Jan 25, 3:44 am, Sebastien Lambla s...@serialseb.com wrote: But doing that has a consequence: All my properties in the one model must be virtual, even the ones that are not related to fields in my database. That's because the object is created as a proxy. Any of your property may have access or rely on other properties that need to be hydrated from the db. They all need to be virtual so that the first cal can trigger the load. This is an nhibernate thing. -- Seb _ Windows Live Messenger just got better .Video display pics, contact updates more.http://www.download.live.com/messenger --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Fluent NHibernate group. To post to this group, send email to fluent-nhibernate@googlegroups.com To unsubscribe from this group, send email to fluent-nhibernate+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/fluent-nhibernate?hl=en -~--~~~~--~~--~--~---