Hi,
We are experiencing the following problem with NHibernate second level
cache: when a new entity with child sub-entities is inserted into the
db then it seems that the entity itself is put into the cache but its
child entities are not.
For example: we define a customer with multiple contacts:
     public class CustomerDTO
     {
         public virtual long Id{ get; set; }
         public virtual int RowVersion { get; set; }
         public virtual IList<ContactDTO> ContactDTOs { get; set; }
     }

     public class ContactDTO
     {
         public virtual long Id{ get; set; }
         public virtual int RowVersion { get; set; }
          public virtual CustomerDTO CustomerDTO { get; set; }
     }

 and the relevant mappings are as follows:
        public CustomerDTOMap() : ClassMap<CustomerDTO>
        {
            base.Cache.ReadWrite();
            base.Table("customer");
            base.DynamicUpdate();
            base.Version(x =>
x.RowVersion).Column("row_version").Not.Nullable();
            base.Id(x => x.Id).Column("id").GeneratedBy.Assigned();

            base.HasMany(x =>
x.ContactDTOs).KeyColumn("cust_id").Cascade.SaveUpdate().Inverse().Cache.ReadWrite();
        }

        public ContactDTOMap() : ClassMap<ContactDTO>
        {
            base.Cache.ReadWrite();
            base.table("contact");
            base.DynamicUpdate();
            base.Version(x =>
x.RowVersion).Column("row_version").Not.Nullable();
            base.Id(x => x.Id).Column("id").GeneratedBy.Assigned();

            base.References(x =>
x.CustomerDTO).Column("cust_id").Not.Nullable();
        }


Our simplified AddCustomer WCF service looks like this:
                var customerDTO = MapContract(customerContract);  //
maps WCFdata  contract into dto
                using (var tx = Session.BeginTransaction())
                {
                    Session.Save(customerDTO);
                    tx.Commit();
                }

And here's RetrieveCustomer:
                var customerDTO =
Session.Get<CustomerDTO>(customerId);
                var customerContract = MapDTO(customerDTO); // maps
dto back to WCF data contract

After calling AddCustomer the very first RetrieveCustomer gets
CustomerDTO from the cache but goes to the db for contacts; all
subsequent RetrieveCustomer calls do not generate any SELECTS but
return all data straight from the cache.  Does anybody know what’s the
root cause of this behavior and what we need to do to make sure child
entities are cached as they are inserted into the db?
Thanks

-- 
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.

Reply via email to