LazyLoad doesn't work with HasOne
Comments are currently closed for this discussion. You can start a new one.
3 people watching.
-
New Issue
-
Conversation Started
-
The discussion is closed
No more actions from Fluent NHibernate or the discussion starter are required.
-
Re-open the discussion Re-open the discussion
Private Permissions
This discussion is private. Only you and Fluent NHibernate support staff can see and reply to it.
Recent Discussions
24 Feb, 2011 11:35 AM | PersistenceSpecification returns "no persister found for" when persisting a List of Enums. | |
10 Feb, 2011 04:30 AM | Deleted object would be re-saved by cascade | |
09 Feb, 2011 06:02 PM | How to specify optimistic-lock="false" on Property ? | |
09 Feb, 2011 08:38 AM | Assembly qualified type names on filter parameters | |
08 Feb, 2011 04:03 PM | HasMany() Collection of concrete Subclass |
08 Feb, 2011 09:49 AM | LazyLoad doesn't work with HasOne | |
02 Feb, 2011 11:40 AM | Convention for collection with backing field prefixed with underscore | |
01 Feb, 2011 11:50 AM | Conventions for ICompositeUserTypes and field overrides | |
01 Feb, 2011 11:21 AM | NHibernate Override<> for many-to-any | |
26 Jan, 2011 11:26 AM | PersistenceSpecification wrong order for CheckComponentMap (MySQL, MsSQL) |
2 Posted by Ivan Monteiro on 22 Dec, 2010 12:11 PM
Yes, I have it too. Even putting .LazyLoad() in the HasOne mapping doesn't help.
Support Staff 3 Posted by Paul Batum on 25 Dec, 2010 12:35 AM
Can you elaborate on what the problem is? Have you tried exporting
your mappings and inspecting the xml to see if the xml is being
correctly generated?
See here for info on exporting mappings:
http://wiki.fluentnhibernate.org/Fluent_configuration#Exporting_mappings
Paul Batum
4 Posted by Ivan Monteiro Cantalice on 25 Dec, 2010 03:12 PM
Hi, the problem is that even with the latest version of FluentNhibernate,
when I get an object that has One-To-One in mapping, NHibernate generates
one query for the main object with jois to all related one-to-one
relationships, even specifying LazyLoad() in the Fluent Mapping. It would be
better if those related objects would really be lazy loaded.
Here is the one-to-one exported mapping of the Usuario class:
<one-to-one class="Novapangeia.Dominio.Tecnologia, Novapangeia.Dominio,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" lazy="proxy"
name="tecnologias" property-ref="Usuario" />
<one-to-one class="Novapangeia.Dominio.Estoque, Novapangeia.Dominio,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" lazy="proxy"
name="recursos" property-ref="Usuario" />
<one-to-one class="Novapangeia.Dominio.Construcao, Novapangeia.Dominio,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" lazy="proxy"
name="construcoes" property-ref="Usuario" />
Here is the Fluent Mapping:
public class UsuarioMapping : ClassMap<Usuario>
{
public UsuarioMapping()
{
Table("usuario");
Id(x => x.Id, "id").UnsavedValue(0);
/* Omitted to breviety sake*/
HasOne(x => x.tecnologias)
.PropertyRef(x => x.Usuario)
.LazyLoad();
HasOne(x => x.recursos)
.PropertyRef(x => x.Usuario)
.LazyLoad();
HasOne(x => x.construcoes)
.PropertyRef(x => x.Usuario)
.LazyLoad();
}
}
The generated SQL:
NHibernate.Loader.Loader: {INFO} 12/25 11:59:20 - SELECT usuario0_.id as
id8_3_, usuario0_.login as login8_3_, usuario0_.senha as senha8_3_,
usuario0_.general as general8_3_, usuario0_.cidade as cidade8_3_,
usuario0_.email as email8_3_, usuario0_.coordenada_X as coordenada7_8_3_,
usuario0_.coordenada_Y as coordenada8_8_3_, usuario0_.score as score8_3_,
tecnologia1_.id as id5_0_, tecnologia1_.cavalaria as cavalaria5_0_,
tecnologia1_.engenharia as engenharia5_0_, tecnologia1_.espadas as
espadas5_0_, tecnologia1_.arcos as arcos5_0_, tecnologia1_.lancas as
lancas5_0_, tecnologia1_.usuario_id as usuario7_5_0_, estoque2_.id as
id1_1_, estoque2_.espadas as espadas1_1_, estoque2_.lancas as lancas1_1_,
estoque2_.arcos as arcos1_1_, estoque2_.ouro as ouro1_1_, estoque2_.madeira
as madeira1_1_, estoque2_.comida as comida1_1_, estoque2_.minerio as
minerio1_1_, estoque2_.usuario_id as usuario9_1_1_, construcao3_.id as
id0_2_, construcao3_.muralha as muralha0_2_, construcao3_.torres as
torres0_2_, construcao3_.armazem as armazem0_2_, construcao3_.estabulo as
estabulo0_2_, construcao3_.quartel as quartel0_2_, construcao3_.mercado as
mercado0_2_, construcao3_.mina as mina0_2_, construcao3_.fazenda as
fazenda0_2_, construcao3_.serraria as serraria0_2_, construcao3_.usuario_id
as usuario11_0_2_ FROM usuario usuario0_ left outer join tecnologia
tecnologia1_ on usuario0_.id=tecnologia1_.usuario_id left outer join estoque
estoque2_ on usuario0_.id=estoque2_.usuario_id left outer join construcao
construcao3_ on usuario0_.id=construcao3_.usuario_id WHERE usuario0_.id=?p0
2010/12/24 Paul Batum <
***@tenderapp.com<tender%***@tenderapp.com>
>
Support Staff 5 Posted by Paul Batum on 26 Dec, 2010 12:37 PM
You might find this relevant:
http://stackoverflow.com/questions/389026/nhibernate-how-to-enable-lazy-loading-on-one-to-one-mapping
On Sun, Dec 26, 2010 at 2:13 AM, Ivan Monteiro Cantalice <
***@tenderapp.com<tender%***@tenderapp.com>
> wrote:
6 Posted by TDV on 08 Feb, 2011 09:49 AM
Thank you Paul!
Discussion can be closed.
TDV closed this discussion on 08 Feb, 2011 03:56 PM.