This is the current status of this issue:

- If the entity is mapped as lazy and the collection is mapped as
lazy, the collection property is null (!)
- If the entity is mapped as lazy and the collection is mapped as not
lazy, the collection property is null (!)
- If the entity is mapped as not lazy and the collection is mapped as
lazy, the collection is lazy loaded
- If the entity is mapped as not lazy and the collection is mapped as
not lazy, the collection is lazy loaded (!)

So, the collection is always null when the entity is mapped as lazy. I
am using mapping by code with the latest trunk version (as of 12:00 of
today).

Can anyone confirm this is an issue? If so, I will create a JIRA
issue.

Thanks,

RP


On Apr 8, 5:43 am, Ricardo Peres <rjpe...@gmail.com> wrote:
> Why is that? I'm loading it from the DB, NHibernate should create it
> itself. In fact, it does, if I don't use lazy loading.
>
> On Apr 8, 12:49 am, belvasis...@googlemail.com wrote:
>
>
>
>
>
>
>
> > You have to create the instance of the IEnumerable<Order> by yourself so  
> > that NH can use it, just as you would do it without using NH.
>
> > Am schrieb Ricardo Peres <rjpe...@gmail.com>:
>
> > > Hello, again!
> > > When retrieving an entity, a collection property is always null, even
> > > when I try to force eager loading:
> > > using (ISession session = factory.OpenSession())
> > > {
> > > Customer c1 = session.Get(2002L);
> > > Customer c2 = session.CreateQuery("from Customer c join fetch
> > > c.Orders where c.Id = 2002").UniqueResult();
> > > Customer c3 = session.Query().Where(x => x.Id ==
> > > 2002).Fetch(x => x.Orders).Single();
> > > //c1.Orders == c2.Orders == c3.Orders == null
> > > }
> > > mapper.Class(ca =>
> > > {
> > > ca.Table("`CUSTOMER`");
> > > ca.Lazy(true);
> > > ca.Id(x => x.Id, map =>
> > > {
> > > map.Column("`ID`");
> > > map.Generator(Generators.HighLow, g => g.Params(new { max_lo =
> > > "1000" }));
> > > });
> > > ca.NaturalId(x => x.Property(c => c.Name));
> > > ca.Property(x => x.Name, p =>
> > > {
> > > p.NotNullable(true);
> > > p.Column("`NAME`");
> > > });
> > > ca.Property(x => x.Address, p =>
> > > {
> > > p.NotNullable(false);
> > > p.Column("`ADDRESS`");
> > > });
> > > ca.Set(c => c.Orders, c =>
> > > {
> > > c.Key(x => x.Column("`CUSTOMERID`"));
> > > c.Lazy(CollectionLazy.Lazy);
> > > c.Inverse(true);
> > > c.Cascade(Cascade.All);
> > > }, c => c.OneToMany());
> > > });
> > > mapper.Class(ca =>
> > > {
> > > ca.Table("`ORDER`");
> > > ca.Lazy(false);
> > > ca.Id(x => x.Id, map =>
> > > {
> > > map.Column("`ID`");
> > > map.Generator(Generators.HighLow, g => g.Params(new { max_lo =
> > > "1000" }));
> > > });
> > > ca.Property(x => x.Date, x =>
> > > {
> > > x.NotNullable(true);
> > > x.Column("`DATE`");
> > > });
> > > ca.ManyToOne(c => c.Customer, a =>
> > > {
> > > a.Column("`CUSTOMERID`");
> > > a.NotNullable(true);
> > > a.Cascade(Cascade.All);
> > > a.Fetch(FetchKind.Join);
> > > });
> > > }
> > > public class Customer
> > > {
> > > public virtual Int64 Id { get; private set; }
> > > public virtual String Name { get; set; }
> > > public virtual String Address { get; set; }
> > > public virtual IEnumerable Orders { get; private set; }
> > > }
> > > public class Order
> > > {
> > > public virtual Int64 Id { get; private set; }
> > > public virtual DateTime Date { get; set; }
> > > public virtual Customer Customer { get; set; }
> > > }
> > > Shouldn't the Orders property be a proxy? I am using as the default
> > > proxy factory factory the new
> > > NHibernate.ByteCode.DefaultProxyFactoryFactory class.
> > > If I map the set as not lazy, the Orders collection is instantiated
> > > and loaded appropriately:
> > > ca.Set(c => c.Orders, c =>
> > > {
> > > c.Key(x => x.Column("`CUSTOMERID`"));
> > > c.Lazy(CollectionLazy.NoLazy);
> > > c.Inverse(true);
> > > c.Cascade(Cascade.All);
> > > }, c => c.OneToMany());
> > > Finally, if I have a String property marked as lazy, and the Orders
> > > collection as not lazy, the Orders is again null:
> > > mapper.Class(ca =>
> > > {
> > > ca.Table("`CUSTOMER`");
> > > ca.Lazy(true);
> > > ca.Id(x => x.Id, map =>
> > > {
> > > map.Column("`ID`");
> > > map.Generator(Generators.HighLow, g => g.Params(new { max_lo =
> > > "1000" }));
> > > });
> > > ca.NaturalId(x => x.Property(c => c.Name));
> > > ca.Property(x => x.Name, p =>
> > > {
> > > p.NotNullable(true);
> > > p.Column("`NAME`");
> > > });
> > > ca.Property(x => x.Address, p =>
> > > {
> > > p.NotNullable(false);
> > > p.Column("`ADDRESS`");
> > > p.Lazy(true);
> > > });
> > > ca.Set(c => c.Orders, c =>
> > > {
> > > c.Key(x => x.Column("`CUSTOMERID`"));
> > > c.Lazy(CollectionLazy.NoLazy);
> > > c.Inverse(true);
> > > c.Cascade(Cascade.All);
> > > }, c => c.OneToMany());
> > > });
> > > Is this a bug? Yes, I understand the mapper is quite new... I am using
> > > the latest trunk version, haven't tried with HBM.XML, though.
> > > Thanks,
> > > RP
> > > --
> > > You received this message because you are subscribed to the Google  
> > > Groups "nhusers" group.
> > > To post to this group, send email to nhusers@googlegroups.com.
> > > To unsubscribe from this group, send email to  
> > > nhusers+unsubscr...@googlegroups.com.
> > > For more options, visit this group at  
> > >http://groups.google.com/group/nhusers?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to nhusers@googlegroups.com.
To unsubscribe from this group, send email to 
nhusers+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.

Reply via email to