.Cacheable().Fetch() throws 'Exception occurred getter of xxx'

135 views
Skip to first unread message

Segura, Eduardo [Tech]

unread,
Aug 17, 2010, 1:28:33 PM8/17/10
to nhu...@googlegroups.com

I’m wondering if this is the right way to use second-level caching along with eagerly loading a collection.

This code is equivalent to a query that we are issuing from a fairly large application. I’ve stripped it down to the very minimum while still throwing the exception.

(My apologies for the rather large email, but I want to provide as much information up-front as possible)

 

I have this test set up:

 

        [TestMethod]

        public void FindWithFetchAndCacheableTest()

        {

            IPersistenceService ps = PersistenceServiceFactory.CreateService(PersistenceServiceType.Hibernate);

 

            IList<ParentObject> pos = ps.Find<ParentObject, IQueryable<ParentObject>>(ParentObjects =>

                from po in ParentObjects

                select po)

                .Cacheable()

                .Fetch(po => po.ChildObjects).ToList();

 

            Assert.IsTrue(pos.Count > 0);

        }

 

My uneducated guess:

--------------------------------------

The lambda expression in Fetch() is being used as a ‘resultTransfomer’ here:

(NHibernate.Hql.Ast.ANTLR.Loader.QueryLoader.cs:line 335, using NH3.0.0Alpha1)

 

protected override object GetResultColumnOrRow(object[] row, IResultTransformer resultTransformer, IDataReader rs,

ISessionImplementor session)

{

                row = ToResultRow(row); <-- after this assignment, row is an Array[1] holding my object

                bool hasTransform = HasSelectNew || resultTransformer != null;  <-- at this point, resultTransformer has a lambda

 

                …

 

                else if (!hasTransform)

                {

                                return row.Length == 1 ? row[0] : row; <-- the object is not extracted from the array, because of the lambda

                }

}

 

And this method ends up returning an array (object[1] = [{ ParentObject}]), instead of returning the object itself.

 

Then later on, since the ‘object[1]’ array doesn’t have an ‘Id’ property, this line throws the exception:

(NHibernate.Properties.BasicPropertyAccessor.cs:Line 207 (BasicGetter.Get)):

public object Get(object target)

{

                try

                {

                                return property.GetValue(target, new object[0]); <-- target is not {ParentObject}, but an object[1] instead

                }

                catch (Exception e)

                {

                                throw new PropertyAccessException(e, "Exception occurred", false, clazz, propertyName);

                }

}

 

My classes:

------------------------------------------------------

 

    public class ParentObject

    {

        public virtual int Id { get; set; }

        public virtual string Name { get; set; }

        public virtual ISet<ChildObject> ChildObjects { get; set; }

 

        public virtual void AddChildObject(ChildObject co)

        {

            this.ChildObjects.Add(co);

            co.Parent = this;

        }

    }

 

    public class ChildObject

    {

        public virtual int Id { get; set; }

        public virtual string Name { get; set; }

        public virtual ParentObject Parent { get; set; }

    }

 

 

Mappings:

----------------------------------------

<?xml version="1.0" encoding="utf-8" ?>

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" auto-import="true">

  <class name="PersistenceLayer.Test.Model.ParentObject, PersistenceLayer.Test">

    <cache usage="read-write"/>

    <id name="Id">

      <generator class="native"/>

    </id>

    <property name="Name"/>

    <set name="ChildObjects" inverse="true" cascade="all-delete-orphan">

      <cache usage="read-write"/>

      <key column="ParentId"/>

      <one-to-many class="PersistenceLayer.Test.Model.ChildObject"/>

    </set>

  </class>

</hibernate-mapping>

 

 

<?xml version="1.0" encoding="utf-8" ?>

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" auto-import="true">

  <class name="PersistenceLayer.Test.Model.ChildObject, PersistenceLayer.Test">

    <cache usage="read-write"/>

    <id name="Id">

      <generator class="native"/>

    </id>

    <property name="Name"/>

    <many-to-one name="Parent" column="ParentId" not-null="true"/>

  </class>

</hibernate-mapping>

 

 

 

But it throws this exception:

 

Test method PersistenceLayer.Test.PersistenceServiceTest.FindWithFetchAndCacheableTest threw exception:  NHibernate.PropertyAccessException: Exception occurred getter of PersistenceLayer.Test.Model.ParentObject.Id --->  System.Reflection.TargetException: Object does not match target type..

System.Reflection.RuntimeMethodInfo.CheckConsistency(Object target)

System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)

System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)

System.Reflection.RuntimePropertyInfo.GetValue(Object obj, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo culture)

System.Reflection.RuntimePropertyInfo.GetValue(Object obj, Object[] index)

NHibernate.Properties.BasicPropertyAccessor.BasicGetter.Get(Object target) in d:\CSharp\NH\nhibernate\src\NHibernate\Properties\BasicPropertyAccessor.cs: line 207

NHibernate.Properties.BasicPropertyAccessor.BasicGetter.Get(Object target) in d:\CSharp\NH\nhibernate\src\NHibernate\Properties\BasicPropertyAccessor.cs: line 211

NHibernate.Tuple.Entity.AbstractEntityTuplizer.GetIdentifier(Object entity) in d:\CSharp\NH\nhibernate\src\NHibernate\Tuple\Entity\AbstractEntityTuplizer.cs: line 139

NHibernate.Persister.Entity.AbstractEntityPersister.GetIdentifier(Object obj, EntityMode entityMode) in d:\CSharp\NH\nhibernate\src\NHibernate\Persister\Entity\AbstractEntityPersister.cs: line 3838

NHibernate.Persister.Entity.AbstractEntityPersister.IsTransient(Object entity, ISessionImplementor session) in d:\CSharp\NH\nhibernate\src\NHibernate\Persister\Entity\AbstractEntityPersister.cs: line 3629

NHibernate.Engine.ForeignKeys.IsTransient(String entityName, Object entity, Nullable`1 assumed, ISessionImplementor session) in d:\CSharp\NH\nhibernate\src\NHibernate\Engine\ForeignKeys.cs: line 193

NHibernate.Engine.ForeignKeys.GetEntityIdentifierIfNotUnsaved(String entityName, Object entity, ISessionImplementor session) in d:\CSharp\NH\nhibernate\src\NHibernate\Engine\ForeignKeys.cs: line 249

NHibernate.Type.ManyToOneType.Disassemble(Object value, ISessionImplementor session, Object owner) in d:\CSharp\NH\nhibernate\src\NHibernate\Type\ManyToOneType.cs: line 137

NHibernate.Cache.StandardQueryCache.Put(QueryKey key, ICacheAssembler[] returnTypes, IList result, Boolean isNaturalKeyLookup, ISessionImplementor session) in d:\CSharp\NH\nhibernate\src\NHibernate\Cache\StandardQueryCache.cs: line 82

NHibernate.Loader.Loader.PutResultInQueryCache(ISessionImplementor session, QueryParameters queryParameters, IType[] resultTypes, IQueryCache queryCache, QueryKey key, IList result) in d:\CSharp\NH\nhibernate\src\NHibernate\Loader\Loader.cs: line 1627

NHibernate.Loader.Loader.ListUsingQueryCache(ISessionImplementor session, QueryParameters queryParameters, ISet`1 querySpaces, IType[] resultTypes) in d:\CSharp\NH\nhibernate\src\NHibernate\Loader\Loader.cs: line 1593

NHibernate.Loader.Loader.List(ISessionImplementor session, QueryParameters queryParameters, ISet`1 querySpaces, IType[] resultTypes) in d:\CSharp\NH\nhibernate\src\NHibernate\Loader\Loader.cs: line 1567

NHibernate.Hql.Ast.ANTLR.Loader.QueryLoader.List(ISessionImplementor session, QueryParameters queryParameters) in d:\CSharp\NH\nhibernate\src\NHibernate\Hql\Ast\ANTLR\Loader\QueryLoader.cs: line 298

NHibernate.Hql.Ast.ANTLR.QueryTranslatorImpl.List(ISessionImplementor session, QueryParameters queryParameters) in d:\CSharp\NH\nhibernate\src\NHibernate\Hql\Ast\ANTLR\QueryTranslatorImpl.cs: line 110

NHibernate.Engine.Query.HQLQueryPlan.PerformList(QueryParameters queryParameters, ISessionImplementor session, IList results) in d:\CSharp\NH\nhibernate\src\NHibernate\Engine\Query\HQLQueryPlan.cs: line 105

NHibernate.Impl.SessionImpl.List(IQueryExpression queryExpression, QueryParameters queryParameters, IList results) in d:\CSharp\NH\nhibernate\src\NHibernate\Impl\SessionImpl.cs: line 679

NHibernate.Impl.SessionImpl.List(IQueryExpression queryExpression, QueryParameters parameters) in d:\CSharp\NH\nhibernate\src\NHibernate\Impl\SessionImpl.cs: line 655

NHibernate.Impl.ExpressionQueryImpl.List() in d:\CSharp\NH\nhibernate\src\NHibernate\Impl\ExpressionQueryImpl.cs: line 63

NHibernate.Linq.NhQueryProvider.Execute(Expression expression) in d:\CSharp\NH\nhibernate\src\NHibernate\Linq\NhQueryProvider.cs: line 31

NHibernate.Linq.NhQueryProvider.Execute[TResult](Expression expression) in d:\CSharp\NH\nhibernate\src\NHibernate\Linq\NhQueryProvider.cs: line 55

GetEnumerator()

ctor(IEnumerable`1 collection)

System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)

PersistenceLayer.Test.PersistenceServiceTest.FindWithFetchAndCacheableTest() in …..\PersistenceServiceTest.cs: line 345

 

Thanks,

Eduardo

Segura, Eduardo [Tech]

unread,
Aug 19, 2010, 10:08:33 AM8/19/10
to nhu...@googlegroups.com

Hi folks,

 

Could I get your feedback on this one? Am I missing something?

 

Thanks,

Diego Mijelshon

unread,
Aug 19, 2010, 10:28:16 AM8/19/10
to nhu...@googlegroups.com
Well, I don't know what the code of 
IPersistenceService.Find does, but the following works here:
  session.Query<Foo>().Cacheable().Fetch(f => f.Bar).ToList();
And I don't get the idea behind "from po in ParentObjects select po"; that's a noop.

 
    Diego


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

Segura, Eduardo [Tech]

unread,
Aug 19, 2010, 10:38:09 AM8/19/10
to nhu...@googlegroups.com

Hi Diego,

 

Are you running off of the trunk? Because this still throws that exception with Alpha1:

 

IList<ParentObject> pos =

    session.Query<ParentObject>().Cacheable().Fetch(po => po.ChildObjects).ToList();

 

Thanks,

Eduardo

Diego Mijelshon

unread,
Aug 19, 2010, 11:02:34 AM8/19/10
to nhu...@googlegroups.com
Alpha2.
I don't see it caching the query, though... but it returns the correct records.
 
    Diego

Segura, Eduardo [Tech]

unread,
Aug 19, 2010, 4:20:33 PM8/19/10
to nhu...@googlegroups.com

Actually, Alpha2 is also throwing for me. I’m attaching the new stack trace so you can verify that I’m using Alpha2 (the line numbers for the stack vary slightly, reflecting what has been committed to the trunk since Alpha1).

 

I’ve also updated my little test, just to check if the fact that you are not eagerly fetching a collection, but just a single object, ‘Bar’:

  session.Query<Foo>().Cacheable().Fetch(f => f.Bar).ToList();

could be what’s causing this, but unfortunately the result is the same for me:

 

// this line is ok

IList<ParentObject> pos2 = session.Query<ParentObject>().Cacheable().ToList();

 

// this line is ok

IList<ChildObject> cos2 = session.Query<ChildObject>().Cacheable().ToList();

 

// this throws with Alpha2

IList<ChildObject> cos = session.Query<ChildObject>()

                .Cacheable()

                .Fetch(co => co.Parent).ToList();

 

// this throws with Alpha2

IList<ParentObject> pos = session.Query<ParentObject>()

                .Cacheable()

                .Fetch(po => po.ChildObjects).ToList();

 

I did see the behavior you describe, ‘don't see it caching the query’, but only briefly, just before rebuilding the whole project. (I’m using memcached, and since there is no NHContrib for Alpha2 yet, after a rebuild I started getting errors regarding not being able to load 3.0.0.1001, so I removed the reference and started using HashtableCache instead).

 

So, I’m wondering if maybe this is what happened for you as well. Could you confirm?

 

Eduardo

 

Stack trace:

---------------

System.Reflection.RuntimeMethodInfo.CheckConsistency(Object target)

System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)

System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)

System.Reflection.RuntimePropertyInfo.GetValue(Object obj, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo culture)

System.Reflection.RuntimePropertyInfo.GetValue(Object obj, Object[] index)

NHibernate.Properties.BasicPropertyAccessor.BasicGetter.Get(Object target) in d:\CSharp\NH\nhibernate\src\NHibernate\Properties\BasicPropertyAccessor.cs: line 207

NHibernate.Properties.BasicPropertyAccessor.BasicGetter.Get(Object target) in d:\CSharp\NH\nhibernate\src\NHibernate\Properties\BasicPropertyAccessor.cs: line 211

NHibernate.Tuple.Entity.AbstractEntityTuplizer.GetIdentifier(Object entity) in d:\CSharp\NH\nhibernate\src\NHibernate\Tuple\Entity\AbstractEntityTuplizer.cs: line 139

NHibernate.Persister.Entity.AbstractEntityPersister.GetIdentifier(Object obj, EntityMode entityMode) in d:\CSharp\NH\nhibernate\src\NHibernate\Persister\Entity\AbstractEntityPersister.cs: line 3841

NHibernate.Persister.Entity.AbstractEntityPersister.IsTransient(Object entity, ISessionImplementor session) in d:\CSharp\NH\nhibernate\src\NHibernate\Persister\Entity\AbstractEntityPersister.cs: line 3632

NHibernate.Engine.ForeignKeys.IsTransient(String entityName, Object entity, Nullable`1 assumed, ISessionImplementor session) in d:\CSharp\NH\nhibernate\src\NHibernate\Engine\ForeignKeys.cs: line 193

NHibernate.Engine.ForeignKeys.GetEntityIdentifierIfNotUnsaved(String entityName, Object entity, ISessionImplementor session) in d:\CSharp\NH\nhibernate\src\NHibernate\Engine\ForeignKeys.cs: line 249

NHibernate.Type.ManyToOneType.Disassemble(Object value, ISessionImplementor session, Object owner) in d:\CSharp\NH\nhibernate\src\NHibernate\Type\ManyToOneType.cs: line 137

NHibernate.Cache.StandardQueryCache.Put(QueryKey key, ICacheAssembler[] returnTypes, IList result, Boolean isNaturalKeyLookup, ISessionImplementor session) in d:\CSharp\NH\nhibernate\src\NHibernate\Cache\StandardQueryCache.cs: line 82

NHibernate.Loader.Loader.PutResultInQueryCache(ISessionImplementor session, QueryParameters queryParameters, IType[] resultTypes, IQueryCache queryCache, QueryKey key, IList result) in d:\CSharp\NH\nhibernate\src\NHibernate\Loader\Loader.cs: line 1634

NHibernate.Loader.Loader.ListUsingQueryCache(ISessionImplementor session, QueryParameters queryParameters, ISet`1 querySpaces, IType[] resultTypes) in d:\CSharp\NH\nhibernate\src\NHibernate\Loader\Loader.cs: line 1600

NHibernate.Loader.Loader.List(ISessionImplementor session, QueryParameters queryParameters, ISet`1 querySpaces, IType[] resultTypes) in d:\CSharp\NH\nhibernate\src\NHibernate\Loader\Loader.cs: line 1574

NHibernate.Hql.Ast.ANTLR.Loader.QueryLoader.List(ISessionImplementor session, QueryParameters queryParameters) in d:\CSharp\NH\nhibernate\src\NHibernate\Hql\Ast\ANTLR\Loader\QueryLoader.cs: line 298

NHibernate.Hql.Ast.ANTLR.QueryTranslatorImpl.List(ISessionImplementor session, QueryParameters queryParameters) in d:\CSharp\NH\nhibernate\src\NHibernate\Hql\Ast\ANTLR\QueryTranslatorImpl.cs: line 110

NHibernate.Engine.Query.HQLQueryPlan.PerformList(QueryParameters queryParameters, ISessionImplementor session, IList results) in d:\CSharp\NH\nhibernate\src\NHibernate\Engine\Query\HQLQueryPlan.cs: line 105

NHibernate.Impl.SessionImpl.List(IQueryExpression queryExpression, QueryParameters queryParameters, IList results) in d:\CSharp\NH\nhibernate\src\NHibernate\Impl\SessionImpl.cs: line 679

NHibernate.Impl.SessionImpl.List(IQueryExpression queryExpression, QueryParameters parameters) in d:\CSharp\NH\nhibernate\src\NHibernate\Impl\SessionImpl.cs: line 655

NHibernate.Impl.ExpressionQueryImpl.List() in d:\CSharp\NH\nhibernate\src\NHibernate\Impl\ExpressionQueryImpl.cs: line 63

NHibernate.Linq.NhQueryProvider.Execute(Expression expression) in d:\CSharp\NH\nhibernate\src\NHibernate\Linq\NhQueryProvider.cs: line 31

NHibernate.Linq.NhQueryProvider.Execute[TResult](Expression expression) in d:\CSharp\NH\nhibernate\src\NHibernate\Linq\NhQueryProvider.cs: line 55

GetEnumerator()

ctor(IEnumerable`1 collection)

System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)

PersistenceLayer.Test.PersistenceServiceTest.FindWithFetchAndCacheableTest() in ….\PersistenceServiceTest.cs: line 366

Diego Mijelshon

unread,
Aug 20, 2010, 11:17:28 AM8/20/10
to nhusers
After fixing a wrong config setting, all those queries run and are cached without issues.
I only tested with HashtableCacheProvider (this is a proof-of-concept solution)

 
    Diego

Segura, Eduardo [Tech]

unread,
Aug 20, 2010, 2:38:28 PM8/20/10
to nhu...@googlegroups.com

Care to share your solution? I can’t seem to find the difference between your environment and mine, and still doesn’t work for me.

Diego Mijelshon

unread,
Aug 20, 2010, 2:55:12 PM8/20/10
to nhu...@googlegroups.com
Sure

Classes:
    public class Foo : Entity<Guid>
    {
        public virtual ICollection<BarBars { getset; }
    }

    public class Bar : Entity<Guid>
    {
        public virtual Foo Foo { getset; }
    }
Mapping (by ConfORM):
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
  <class name="Foo">
    <id name="Id" type="Guid">
      <generator class="guid.comb" />
    </id>
    <bag name="Bars" inverse="true" cascade="all,delete-orphan">
      <key column="Foo" on-delete="cascade" />
      <one-to-many class="Bar" />
    </bag>
  </class>
  <class name="Bar">
    <id name="Id" type="Guid">
      <generator class="guid.comb" />
    </id>
    <many-to-one name="Foo" />
  </class>
</hibernate-mapping> 

Configuration:
            var config = new Configuration()
                .DataBaseIntegration(db =>
                                         {
                                             db.ConnectionProvider<DriverConnectionProvider>();
                                             db.Driver<SqlClientDriver>();
                                             db.ConnectionString =
                                                 "Data Source=.;Initial Catalog=test;Integrated Security=True";
                                             db.Dialect<MsSql2008Dialect>();
                                             db.LogSqlInConsole = true;
                                             db.LogFormatedSql = true;
                                             db.HqlToSqlSubstitutions = "true 1, false 0";
                                         })
                .Cache(ccp =>
                           {
                               ccp.DefaultExpiration = 60;
                               ccp.Provider<HashtableCacheProvider>();
                           })
                .Proxy(p => p.ProxyFactoryFactory<ProxyFactoryFactory>());
            config.SetProperty(Environment.UseQueryCache"true");

Queries:

                session.Query<Foo>().Cacheable().ToList();
                session.Query<Bar>().Cacheable().ToList();
                session.Query<Foo>().Cacheable().Fetch(x => x.Bars).ToList();
                session.Query<Bar>().Cacheable().Fetch(x => x.Foo).ToList();

    Diego

Segura, Eduardo [Tech]

unread,
Aug 20, 2010, 5:14:58 PM8/20/10
to nhu...@googlegroups.com

Weird, this example throws the same exception for me (attached at the end). There were a few minor things that I had to add/change:

 

Classes (had to add Entity):

public class Entity<T>

{

    public virtual T Id { get; set; }

}

 

Mapping (had to add namespace,assembly):

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"  auto-import="true"

                   namespace="CacheableFetchTest" assembly="CacheableFetchTest">

 

Configuration (tried two):

db.Driver<SqlClientDriver>();

db.ConnectionString = "Data Source=xyz;Initial Catalog=abc;Integrated Security=True";

db.Dialect<MsSql2005Dialect>();

//db.Driver<SqlServerCeDriver>();

//db.ConnectionString = "Data Source=DataModel.sdf";

//db.Dialect<MsSqlCeDialect>();

 

Query:

[TestMethod]

public void TestMethod1()

{

  using(ISession session = sessionFactory.OpenSession())

  using (ITransaction transaction = session.BeginTransaction())

  {

    IList<Foo> foos1 = session.Query<Foo>().Cacheable().ToList();

    IList<Bar> bars1 = session.Query<Bar>().Cacheable().ToList();

    IList<Foo> foos2 = session.Query<Foo>().Cacheable().Fetch(x => x.Bars).ToList();

    IList<Bar> bars2 = session.Query<Bar>().Cacheable().Fetch(x => x.Foo).ToList();

  }

}

 

I’m using ‘Mappings.hbm.xml’ as my mapping file, packaged as ‘Embedded Resource’

Given that we are running almost the same code at this point, I guess the only things left to compare are:

(Unfortunately I can’t email attachments out from this account, otherwise I would be sending you the solution. Maybe over the weekend, if you are around/interested. At this point it can’t hurt to start trying this on other systems)

 

Tables:

/****** Object:  Table [dbo].[Foo]    Script Date: 08/20/2010 16:57:04 ******/

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

CREATE TABLE [dbo].[Foo](

      [Id] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,

 CONSTRAINT [PK_Foo] PRIMARY KEY CLUSTERED

(

      [Id] ASC

) ON [PRIMARY]

) ON [PRIMARY]

 

/****** Object:  Table [dbo].[Bar]    Script Date: 08/20/2010 16:57:15 ******/

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

CREATE TABLE [dbo].[Bar](

      [Id] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,

      [Foo] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,

 CONSTRAINT [PK_Bar] PRIMARY KEY CLUSTERED

(

      [Id] ASC

) ON [PRIMARY]

) ON [PRIMARY]

 

GO

USE [CoreFramework]

GO

ALTER TABLE [dbo].[Bar]  WITH CHECK ADD  CONSTRAINT [FK_Bar_Foo] FOREIGN KEY([Foo])

REFERENCES [dbo].[Foo] ([Id])

 

Usings:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Reflection;

using Microsoft.VisualStudio.TestTools.UnitTesting;

using NHibernate;

using NHibernate.ByteCode.Castle;

using NHibernate.Cache;

using NHibernate.Cfg;

using NHibernate.Cfg.Loquacious;

using NHibernate.Connection;

using NHibernate.Dialect;

using NHibernate.Driver;

using NHibernate.Linq;

 

and Libraries:

-Antlr3.Runtime (3.1.3.42154)

-Castle.Core (1.2.0.0)

-Castle.DynamixProxy2 (2.2.0.0)

-Iesi.Collections (1.0.1.0)

-Microsoft.VisualStudio.QualityTools.UnitTestFramework (9.0.0.0)

-NHibernate (3.0.0.1002)

-NHibernate.ByteCode.Castle (3.0.0.1002)

-Remotion.Data.Linq (1.13.41.2)

-System (2.0.0.0)

-System.Core (3.5.0.0)

-System.Data.SqlServerCe (3.5.1.0)

 

 

The exception with these objects is:

 

Test method CacheableFetchTest.UnitTest1.TestMethod1 threw exception:  NHibernate.PropertyAccessException: Exception occurred getter of CacheableFetchTest.Entity`1[[System.Guid, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].Id --->  System.Reflection.TargetException: Object does not match target type..

System.Reflection.RuntimeMethodInfo.CheckConsistency(Object target)

System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)

System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)

System.Reflection.RuntimePropertyInfo.GetValue(Object obj, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo culture)

System.Reflection.RuntimePropertyInfo.GetValue(Object obj, Object[] index)

NHibernate.Properties.BasicPropertyAccessor.BasicGetter.Get(Object target) in d:\CSharp\NH\nhibernate\src\NHibernate\Properties\BasicPropertyAccessor.cs: line 207

NHibernate.Properties.BasicPropertyAccessor.BasicGetter.Get(Object target) in d:\CSharp\NH\nhibernate\src\NHibernate\Properties\BasicPropertyAccessor.cs: line 211

NHibernate.Tuple.Entity.AbstractEntityTuplizer.GetIdentifier(Object entity) in d:\CSharp\NH\nhibernate\src\NHibernate\Tuple\Entity\AbstractEntityTuplizer.cs: line 139

NHibernate.Persister.Entity.AbstractEntityPersister.GetIdentifier(Object obj, EntityMode entityMode) in d:\CSharp\NH\nhibernate\src\NHibernate\Persister\Entity\AbstractEntityPersister.cs: line 3841

NHibernate.Persister.Entity.AbstractEntityPersister.IsTransient(Object entity, ISessionImplementor session) in d:\CSharp\NH\nhibernate\src\NHibernate\Persister\Entity\AbstractEntityPersister.cs: line 3632

NHibernate.Engine.ForeignKeys.IsTransient(String entityName, Object entity, Nullable`1 assumed, ISessionImplementor session) in d:\CSharp\NH\nhibernate\src\NHibernate\Engine\ForeignKeys.cs: line 193

NHibernate.Engine.ForeignKeys.GetEntityIdentifierIfNotUnsaved(String entityName, Object entity, ISessionImplementor session) in d:\CSharp\NH\nhibernate\src\NHibernate\Engine\ForeignKeys.cs: line 249

NHibernate.Type.ManyToOneType.Disassemble(Object value, ISessionImplementor session, Object owner) in d:\CSharp\NH\nhibernate\src\NHibernate\Type\ManyToOneType.cs: line 137

NHibernate.Cache.StandardQueryCache.Put(QueryKey key, ICacheAssembler[] returnTypes, IList result, Boolean isNaturalKeyLookup, ISessionImplementor session) in d:\CSharp\NH\nhibernate\src\NHibernate\Cache\StandardQueryCache.cs: line 82

NHibernate.Loader.Loader.PutResultInQueryCache(ISessionImplementor session, QueryParameters queryParameters, IType[] resultTypes, IQueryCache queryCache, QueryKey key, IList result) in d:\CSharp\NH\nhibernate\src\NHibernate\Loader\Loader.cs: line 1634

NHibernate.Loader.Loader.ListUsingQueryCache(ISessionImplementor session, QueryParameters queryParameters, ISet`1 querySpaces, IType[] resultTypes) in d:\CSharp\NH\nhibernate\src\NHibernate\Loader\Loader.cs: line 1600

NHibernate.Loader.Loader.List(ISessionImplementor session, QueryParameters queryParameters, ISet`1 querySpaces, IType[] resultTypes) in d:\CSharp\NH\nhibernate\src\NHibernate\Loader\Loader.cs: line 1574

NHibernate.Hql.Ast.ANTLR.Loader.QueryLoader.List(ISessionImplementor session, QueryParameters queryParameters) in d:\CSharp\NH\nhibernate\src\NHibernate\Hql\Ast\ANTLR\Loader\QueryLoader.cs: line 298

NHibernate.Hql.Ast.ANTLR.QueryTranslatorImpl.List(ISessionImplementor session, QueryParameters queryParameters) in d:\CSharp\NH\nhibernate\src\NHibernate\Hql\Ast\ANTLR\QueryTranslatorImpl.cs: line 110

NHibernate.Engine.Query.HQLQueryPlan.PerformList(QueryParameters queryParameters, ISessionImplementor session, IList results) in d:\CSharp\NH\nhibernate\src\NHibernate\Engine\Query\HQLQueryPlan.cs: line 105

NHibernate.Impl.SessionImpl.List(IQueryExpression queryExpression, QueryParameters queryParameters, IList results) in d:\CSharp\NH\nhibernate\src\NHibernate\Impl\SessionImpl.cs: line 679

NHibernate.Impl.SessionImpl.List(IQueryExpression queryExpression, QueryParameters parameters) in d:\CSharp\NH\nhibernate\src\NHibernate\Impl\SessionImpl.cs: line 655

NHibernate.Impl.ExpressionQueryImpl.List() in d:\CSharp\NH\nhibernate\src\NHibernate\Impl\ExpressionQueryImpl.cs: line 63

NHibernate.Linq.NhQueryProvider.Execute(Expression expression) in d:\CSharp\NH\nhibernate\src\NHibernate\Linq\NhQueryProvider.cs: line 31

NHibernate.Linq.NhQueryProvider.Execute[TResult](Expression expression) in d:\CSharp\NH\nhibernate\src\NHibernate\Linq\NhQueryProvider.cs: line 55

GetEnumerator()

ctor(IEnumerable`1 collection)

System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)

CacheableFetchTest.UnitTest1.TestMethod1() in …\CacheableFetchTest\CacheableFetchTest\UnitTest1.cs: line 92

 

Thanks,

Eduardo

 

From: nhu...@googlegroups.com [mailto:nhu...@googlegroups.com] On Behalf Of Diego Mijelshon
Sent: Friday, August 20, 2010 2:55 PM
To: nhu...@googlegroups.com
Subject: Re: [nhusers] RE: .Cacheable().Fetch() throws 'Exception occurred getter of xxx'

 

Sure

Diego Mijelshon

unread,
Aug 20, 2010, 8:14:19 PM8/20/10
to nhu...@googlegroups.com
Heh, sorry about the missing Entity<T>.
The only big mistake I see is that you are creating the IDs as Varchar, when they are Guids (uniqueidentifier), which is causing that error.
 
    Diego


--

Segura, Eduardo [Tech]

unread,
Aug 23, 2010, 10:22:11 AM8/23/10
to nhu...@googlegroups.com

Hi Diego,

 

Hope you had a nice weekend.

 

I tried the fix you mentioned, but the results are still the same. And come to think about it, it makes sense since I started this exercise using integers as identifiers.

Remember that the problem is not comparing the identifiers themselves, but that the line that takes the object from the array:

 

else if (!hasTransform)

                {

                                return row.Length == 1 ? row[0] : row; <-- the object is not extracted from the array, because of the lambda

                }

 

Is not being executed.

 

Thoughts?

Diego Mijelshon

unread,
Aug 23, 2010, 10:36:06 AM8/23/10
to nhu...@googlegroups.com
No idea... I'm not even looking at the source... it "just works" for me :-)
 
    Diego

Segura, Eduardo [Tech]

unread,
Aug 23, 2010, 11:18:41 AM8/23/10
to nhu...@googlegroups.com

Hah, yeah, I thought you might go that route.

 

Diego, thanks for your responses anyway. I do appreciate the time you put into this.

 

I’m reaching out to the whole community now: It works for him, it doesn’t work for me. Are there any volunteers willing to give this a try? It shouldn’t take more than 10 minutes to launch Visual Studio and create a solution with all the files already included in this thread.

 

Thanks in advance,

Segura, Eduardo [Tech]

unread,
Aug 24, 2010, 6:16:17 PM8/24/10
to nhu...@googlegroups.com

I thought I would share my findings: Two of my coworkers are getting the same exception.

 

I don’t think there is a test case that combines both Cacheable() and Fetch(), is it? I’m looking at NHibernate.Test.Linq.EagerLoadTests and NHibernate.Test.Linq.QueryCacheableTests

 

Would it help if I write a couple of unit test and send them as a patch?

 

Thanks,

Eduardo

 

From: Segura, Eduardo [Tech]
Sent: Monday, August 23, 2010 11:19 AM
To: 'nhu...@googlegroups.com'
Subject: RE: [nhusers] RE: .Cacheable().Fetch() throws 'Exception occurred getter of xxx'

 

Hah, yeah, I thought you might go that route.

 

Diego, thanks for your responses anyway. I do appreciate the time you put into this.

 

I’m reaching out to the whole community now: It works for him, it doesn’t work for me. Are there any volunteers willing to give this a try? It shouldn’t take more than 10 minutes to launch Visual Studio and create a solution with all the files already included in this thread.

 

Thanks in advance,

Eduardo

 

From: nhu...@googlegroups.com [mailto:nhu...@googlegroups.com] On Behalf Of Diego Mijelshon


Sent: Monday, August 23, 2010 10:36 AM

Dean Ward

unread,
Sep 23, 2010, 11:21:46 AM9/23/10
to nhusers
Hi Eduardo,

I'm seeing the same problem here. It's definitely related to it
returning an object[1] instead of the actual entity as you've stated.
My unit test looks identical to yours - do you want to put it in JIRA
or will I?

Cheers,

Dean

On Aug 24, 11:16 pm, "Segura, Eduardo [Tech]" <Eduardo.Seg...@gs.com>
wrote:
> I thought I would share my findings: Two of my coworkers are getting the same exception.
>
> I don't think there is a test case that combines both Cacheable() and Fetch(), is it? I'm looking at NHibernate.Test.Linq.EagerLoadTests and NHibernate.Test.Linq.QueryCacheableTests
>
> Would it help if I write a couple of unit test and send them as a patch?
>
> Thanks,
> Eduardo
>
> From: Segura, Eduardo [Tech]
> Sent: Monday, August 23, 2010 11:19 AM
> To: 'nhu...@googlegroups.com'
> Subject: RE: [nhusers] RE: .Cacheable().Fetch() throws 'Exception occurred getter of xxx'
>
> Hah, yeah, I thought you might go that route.
>
> Diego, thanks for your responses anyway. I do appreciate the time you put into this.
>
> I'm reaching out to the whole community now: It works for him, it doesn't work for me. Are there any volunteers willing to give this a try? It shouldn't take more than 10 minutes to launch Visual Studio and create a solution with all the files already included in this thread.
>
> Thanks in advance,
> Eduardo
>
> From: nhu...@googlegroups.com [mailto:nhu...@googlegroups.com] On Behalf Of Diego Mijelshon
> Sent: Monday, August 23, 2010 10:36 AM
> To: nhu...@googlegroups.com
> Subject: Re: [nhusers] RE: .Cacheable().Fetch() throws 'Exception occurred getter of xxx'
>
> No idea... I'm not even looking at the source... it "just works" for me :-)
>
>     Diego
> On Mon, Aug 23, 2010 at 11:22, Segura, Eduardo [Tech] <Eduardo.Seg...@gs.com<mailto:Eduardo.Seg...@gs.com>> wrote:
> Hi Diego,
>
> Hope you had a nice weekend.
>
> I tried the fix you mentioned, but the results are still the same. And come to think about it, it makes sense since I started this exercise using integers as identifiers.
> Remember that the problem is not comparing the identifiers themselves, but that the line that takes the object from the array:
>
> else if (!hasTransform)
>                 {
>                                 return row.Length == 1 ? row[0] : row; <-- the object is not extracted from the array, because of the lambda
>                 }
>
> Is not being executed.
>
> Thoughts?
> Eduardo
>
> From: nhu...@googlegroups.com<mailto:nhu...@googlegroups.com> [mailto:nhu...@googlegroups.com<mailto:nhu...@googlegroups.com>] On Behalf Of Diego Mijelshon
> Sent: Friday, August 20, 2010 8:14 PM
>
> To: nhu...@googlegroups.com<mailto:nhu...@googlegroups.com>
> Subject: Re: [nhusers] RE: .Cacheable().Fetch() throws 'Exception occurred getter of xxx'
>
> Heh, sorry about the missing Entity<T>.
> The only big mistake I see is that you are creating the IDs as Varchar, when they are Guids (uniqueidentifier), which is causing that error.
>
>     Diego
> NHibernate.Tuple.Entity.AbstractEntityTuplizer.GetIdentifier(Object entity) in d:\CSharp\NH\nhibernate\src\NHibernate\Tuple\Entity\AbstractEntityTuplizer. cs: line 139
> NHibernate.Persister.Entity.AbstractEntityPersister.GetIdentifier(Object obj, EntityMode entityMode) in d:\CSharp\NH\nhibernate\src\NHibernate\Persister\Entity\AbstractEntityPersi ster.cs: line 3841
> NHibernate.Persister.Entity.AbstractEntityPersister.IsTransient(Object entity, ISessionImplementor session) in d:\CSharp\NH\nhibernate\src\NHibernate\Persister\Entity\AbstractEntityPersi ster.cs: line 3632
> NHibernate.Engine.ForeignKeys.IsTransient(String entityName, Object entity, Nullable`1 assumed, ISessionImplementor session) in d:\CSharp\NH\nhibernate\src\NHibernate\Engine\ForeignKeys.cs: line 193
> NHibernate.Engine.ForeignKeys.GetEntityIdentifierIfNotUnsaved(String entityName, Object entity, ISessionImplementor session) in d:\CSharp\NH\nhibernate\src\NHibernate\Engine\ForeignKeys.cs: line 249
> NHibernate.Type.ManyToOneType.Disassemble(Object value, ISessionImplementor session, Object owner) in d:\CSharp\NH\nhibernate\src\NHibernate\Type\ManyToOneType.cs: line 137
> NHibernate.Cache.StandardQueryCache.Put(QueryKey key, ICacheAssembler[] returnTypes, IList result, Boolean isNaturalKeyLookup, ISessionImplementor session) in d:\CSharp\NH\nhibernate\src\NHibernate\Cache\StandardQueryCache.cs: line 82
> NHibernate.Loader.Loader.PutResultInQueryCache(ISessionImplementor session, QueryParameters queryParameters, IType[] resultTypes, IQueryCache queryCache, QueryKey key, IList result) in d:\CSharp\NH\nhibernate\src\NHibernate\Loader\Loader.cs: line 1634
> NHibernate.Loader.Loader.ListUsingQueryCache(ISessionImplementor session, QueryParameters queryParameters, ISet`1 querySpaces, IType[] resultTypes) in d:\CSharp\NH\nhibernate\src\NHibernate\Loader\Loader.cs: line 1600
> NHibernate.Loader.Loader.List(ISessionImplementor session, QueryParameters queryParameters, ISet`1 querySpaces, IType[] resultTypes) in d:\CSharp\NH\nhibernate\src\NHibernate\Loader\Loader.cs: line 1574
> NHibernate.Hql.Ast.ANTLR.Loader.QueryLoader.List(ISessionImplementor session, QueryParameters queryParameters) in d:\CSharp\NH\nhibernate\src\NHibernate\Hql\Ast\ANTLR\Loader\QueryLoader.cs: line 298
> NHibernate.Hql.Ast.ANTLR.QueryTranslatorImpl.List(ISessionImplementor session, QueryParameters queryParameters) in d:\CSharp\NH\nhibernate\src\NHibernate\Hql\Ast\ANTLR\QueryTranslatorImpl.cs : line 110
> NHibernate.Engine.Query.HQLQueryPlan.PerformList(QueryParameters queryParameters, ISessionImplementor session, IList results) in d:\CSharp\NH\nhibernate\src\NHibernate\Engine\Query\HQLQueryPlan.cs: line 105
> NHibernate.Impl.SessionImpl.List(IQueryExpression queryExpression, QueryParameters queryParameters, IList results) in ...
>
> read more »

Segura, Eduardo [Tech]

unread,
Sep 23, 2010, 1:58:19 PM9/23/10
to nhu...@googlegroups.com
Hi Dean,

Sorry to hear you are running into the same problem, although it's good to have confirmation. I created a JIRA issue and attached the VS solution to it.

http://216.121.112.228/browse/NHLQ-75

Thanks,
Eduardo

Hi Eduardo,

Cheers,

Dean

--

Luis Fernando

unread,
Mar 21, 2011, 8:51:45 AM3/21/11
to nhu...@googlegroups.com
I also face the probblema in NHibernate 3.1.0. 
Is there a way to fix this?

Luis Fernando

unread,
Mar 21, 2011, 10:04:03 AM3/21/11
to nhu...@googlegroups.com
It seems that it is indeed a Bug http://216.121.112.228/browse/NH-2587

So I ask your help to vote for this bug so it can be solved soon.

Imagine a project already well structured using LinqToNHibernate, but demand was so great that now the optimization
in response time is no longer just an option, now I have to choose between continuing as it is or rewrite all
the data access layer to implement the Cache.

Luis Fernando

unread,
May 3, 2011, 12:33:28 PM5/3/11
to nhu...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages