Note that there are some explanatory texts on larger screens.

plurals
  1. POCollection is not selected with NHibernate-Caching
    primarykey
    data
    text
    <p>I have the fallowing entities:</p> <p>Person Company</p> <p>And then, there is a entity PersonCompany which makes a Relation between Person and Company</p> <p>Mapping for Person is:</p> <pre><code>public class PersonMap : SubclassMap&lt;Person&gt; { public PersonMap() { this.Table("Person"); this.KeyColumn("Id"); this.HasMany(x =&gt; x.PersonCompanys).AsSet().KeyColumn("PersonId").Fetch.Select().Inverse().Cascade.Delete(); } } </code></pre> <p>Company:</p> <pre><code>public class CompanyMap : SubclassMap&lt;Company&gt; { public CompanyMap() { this.Table("Company"); this.KeyColumn("Id"); this.HasMany(x =&gt; x.PersonCompanys).AsSet().KeyColumn("CompanyId").Fetch.Select().Inverse().Cascade.None(); } } </code></pre> <p>and PersonCompany:</p> <pre><code>public class PersonCompanyMap : ClassMap&lt;PersonCompany&gt; { public PersonCompanyMap() { this.Table("PersonCompany"); this.Version(x =&gt; x.ObjectVersion); this.Id(x =&gt; x.Id).GeneratedBy.Assigned(); this.References(x =&gt; x.Company).Column("CompanyId").Fetch.Select(); this.References(x =&gt; x.Person).Column("PersonId").Fetch.Select(); } } </code></pre> <p>SecondLevel-Caching is activated general and for each Entity with Conventions. Also the Caching for the PersonCompanys-Collection:</p> <pre><code>public class CachableConventions : IClassConvention, IHasManyConvention, IHasManyToManyConvention { private static readonly Type[] notCachableTypes = new[] {typeof(Word), typeof(ActivityWord), typeof(DbVersion), typeof(Deleted), typeof(ExchangeSyncState), typeof(Synchronizer), typeof(SerialletterField)}; public void Apply(IClassInstance instance) { if (Array.IndexOf(notCachableTypes, instance.EntityType) &gt;= 0) { return; } instance.Cache.ReadWrite(); } public void Apply(IManyToManyCollectionInstance instance) { if (Array.IndexOf(notCachableTypes, instance.ChildType) &gt;= 0) { return; } instance.Cache.ReadWrite(); } public void Apply(IOneToManyCollectionInstance instance) { if (Array.IndexOf(notCachableTypes, instance.ChildType) &gt;= 0) { return; } instance.Cache.ReadWrite(); } } </code></pre> <p>Now, I create a new Person and after save a new Company and then I add a PersonCompany-Record to the PersonCompanies-Collection.</p> <p>When I after select the created Person, the PersonCompanys-Collection will be empty. When I do the same without SecondLevel-Caching, the PersonCompanys-Collection contains the created Entity.</p> <p>Does someone know, what can going wrong here?</p> <p><strong>Edit - Additional Informations:</strong></p> <p>This steps are causing the problem:</p> <ol> <li>create a new Person with <code>Session.Save(person)</code></li> <li>load the person with <code>person = Session.Get(person.Id)</code></li> <li>get personCompany from the Person with <code>personCompany = person.PersonCompany.FirstOrDefault()</code> (this will be empty)</li> <li>Create a new PersonCompany-Entry with <code>Session.Save(new PersonCompany(Guid.NewGuid()) {Person = person}))</code></li> <li>load the person with <code>person = Session.Get(person.Id)</code></li> <li>now, <code>person.PersonCompany</code> returns an empty list.</li> </ol> <p>When I do not step 3, all is working great.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload