QueryOver does not work with 2nd level cache if entity contains lazy properties

Description

QueryOver<> queries do not work for entities with lazy properties if second-level cache is turned on.

Running such query results in Exception

Entity:

[Serializable] public class UserRole { public virtual int Id { get; set; } public virtual string Name { get;set; } }

Mapping:

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="KudaNado.Core.Entities" assembly="KudaNado.Core" schema="dbo" default-cascade="save-update"> <class name="UserRole" table="UserRole"> <cache usage="nonstrict-read-write" region="LongTerm" /> <id name="Id" column="ID"> <generator class="native" /> </id> <property name="Name" length="50" not-null="true" lazy="true"/> </class> </hibernate-mapping>

Query:

var roles = session.QueryOver<UserRole>().Take(2).List();
ADO.NET Provider: MS SQL "))* .NET Version: 4.0 10:07:46,175 [TestRunnerThread] DEBUG [NHibernate.Impl.SessionImpl] - [session-id=3e29ff04-f9e6-4498-b95c-2783ce545b9a] opened session at timestamp: 5350678798987264, for session factory: [/9cd392140f24407d9243cc6bd4c7693b] 10:07:46,178 [TestRunnerThread] INFO [KudaNado.Integration.Tests.MappingIntegrationTests] - Execute query 10:07:46,210 [TestRunnerThread] DEBUG [NHibernate.Loader.Criteria.CriteriaQueryTranslator] - put criteria= alias=this0_ 10:07:46,242 [TestRunnerThread] DEBUG [NHibernate.AdoNet.AbstractBatcher] - Opened new IDbCommand, open IDbCommands: 1 10:07:46,242 [TestRunnerThread] DEBUG [NHibernate.AdoNet.AbstractBatcher] - Building an IDbCommand object for the SqlString: SELECT TOP (?) this_.ID as ID12_0_ FROM dbo.UserRole this_ 10:07:46,245 [TestRunnerThread] INFO [NHibernate.Loader.Loader] - SELECT TOP (@p0) this_.ID as ID12_0_ FROM dbo.UserRole this_ 10:07:46,249 [TestRunnerThread] DEBUG [NHibernate.SQL] - SELECT TOP (@p0) this_.ID as ID12_0_ FROM dbo.UserRole this_;@p0 = 2 [Type: Int32 (0)] 10:07:46,251 [TestRunnerThread] DEBUG [NHibernate.Connection.DriverConnectionProvider] - Obtaining IDbConnection from Driver 10:07:46,252 [TestRunnerThread] DEBUG [NHibernate.AdoNet.AbstractBatcher] - ExecuteReader took 0 ms 10:07:46,253 [TestRunnerThread] DEBUG [NHibernate.AdoNet.AbstractBatcher] - Opened IDataReader, open IDataReaders: 1 10:07:46,254 [TestRunnerThread] DEBUG [NHibernate.Loader.Loader] - processing result set 10:07:46,254 [TestRunnerThread] DEBUG [NHibernate.Loader.Loader] - result set row: 0 10:07:46,256 [TestRunnerThread] DEBUG [NHibernate.Type.Int32Type] - returning '1' as column: ID12_0_ 10:07:46,259 [TestRunnerThread] DEBUG [NHibernate.Loader.Loader] - result row: EntityKey[KudaNado.Core.Entities.UserRole#1] 10:07:46,263 [TestRunnerThread] DEBUG [NHibernate.Driver.NHybridDataReader] - running NHybridDataReader.Dispose() 10:07:46,263 [TestRunnerThread] DEBUG [NHibernate.AdoNet.AbstractBatcher] - Closed IDataReader, open IDataReaders :0 10:07:46,263 [TestRunnerThread] DEBUG [NHibernate.AdoNet.AbstractBatcher] - DataReader was closed after 11 ms 10:07:46,264 [TestRunnerThread] DEBUG [NHibernate.AdoNet.AbstractBatcher] - Closed IDbCommand, open IDbCommands: 0 10:07:46,266 [TestRunnerThread] DEBUG [NHibernate.Util.ADOExceptionReporter] - could not execute query [ SELECT TOP (@p0) this_.ID as ID12_0_ FROM dbo.UserRole this_ ]
System.NotSupportedException: Specified method is not supported. at NHibernate.Proxy.AbstractProxyFactory.GetFieldInterceptionProxy(Object instanceToWrap) at NHibernate.Tuple.PocoInstantiator.Instantiate() at NHibernate.Tuple.PocoInstantiator.Instantiate(Object id) at NHibernate.Tuple.Entity.AbstractEntityTuplizer.Instantiate(Object id) at NHibernate.Persister.Entity.AbstractEntityPersister.Instantiate(Object id, EntityMode entityMode) at NHibernate.Impl.SessionImpl.Instantiate(IEntityPersister persister, Object id) at NHibernate.Impl.SessionImpl.Instantiate(String clazz, Object id) at NHibernate.Loader.Loader.InstanceNotYetLoaded(IDataReader dr, Int32 i, ILoadable persister, EntityKey key, LockMode lockMode, String rowIdAlias, EntityKey optionalObjectKey, Object optionalObject, IList hydratedObjects, ISessionImplementor session) at NHibernate.Loader.Loader.GetRow(IDataReader rs, ILoadable[] persisters, EntityKey[] keys, Object optionalObject, EntityKey optionalObjectKey, LockMode[] lockModes, IList hydratedObjects, ISessionImplementor session) at NHibernate.Loader.Loader.GetRowFromResultSet(IDataReader resultSet, ISessionImplementor session, QueryParameters queryParameters, LockMode[] lockModeArray, EntityKey optionalObjectKey, IList hydratedObjects, EntityKey[] keys, Boolean returnProxies) at NHibernate.Loader.Loader.DoQuery(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies) at NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies) at NHibernate.Loader.Loader.DoList(ISessionImplementor session, QueryParameters queryParameters) 10:07:46,268 [TestRunnerThread] WARN [NHibernate.Util.ADOExceptionReporter] - System.NotSupportedException: Specified method is not supported. at NHibernate.Proxy.AbstractProxyFactory.GetFieldInterceptionProxy(Object instanceToWrap) at NHibernate.Tuple.PocoInstantiator.Instantiate() at NHibernate.Tuple.PocoInstantiator.Instantiate(Object id) at NHibernate.Tuple.Entity.AbstractEntityTuplizer.Instantiate(Object id) at NHibernate.Persister.Entity.AbstractEntityPersister.Instantiate(Object id, EntityMode entityMode) at NHibernate.Impl.SessionImpl.Instantiate(IEntityPersister persister, Object id) at NHibernate.Impl.SessionImpl.Instantiate(String clazz, Object id) at NHibernate.Loader.Loader.InstanceNotYetLoaded(IDataReader dr, Int32 i, ILoadable persister, EntityKey key, LockMode lockMode, String rowIdAlias, EntityKey optionalObjectKey, Object optionalObject, IList hydratedObjects, ISessionImplementor session) at NHibernate.Loader.Loader.GetRow(IDataReader rs, ILoadable[] persisters, EntityKey[] keys, Object optionalObject, EntityKey optionalObjectKey, LockMode[] lockModes, IList hydratedObjects, ISessionImplementor session) at NHibernate.Loader.Loader.GetRowFromResultSet(IDataReader resultSet, ISessionImplementor session, QueryParameters queryParameters, LockMode[] lockModeArray, EntityKey optionalObjectKey, IList hydratedObjects, EntityKey[] keys, Boolean returnProxies) at NHibernate.Loader.Loader.DoQuery(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies) at NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies) at NHibernate.Loader.Loader.DoList(ISessionImplementor session, QueryParameters queryParameters) 10:07:46,268 [TestRunnerThread] ERROR [NHibernate.Util.ADOExceptionReporter] - Specified method is not supported. 10:07:46,269 [TestRunnerThread] DEBUG [NHibernate.Util.ADOExceptionReporter] - could not execute query [ SELECT TOP (@p0) this_.ID as ID12_0_ FROM dbo.UserRole this_ ] [ SELECT TOP (@p0) this_.ID as ID12_0_ FROM dbo.UserRole this_ ]
System.NotSupportedException: Specified method is not supported. at NHibernate.Proxy.AbstractProxyFactory.GetFieldInterceptionProxy(Object instanceToWrap) at NHibernate.Tuple.PocoInstantiator.Instantiate() at NHibernate.Tuple.PocoInstantiator.Instantiate(Object id) at NHibernate.Tuple.Entity.AbstractEntityTuplizer.Instantiate(Object id) at NHibernate.Persister.Entity.AbstractEntityPersister.Instantiate(Object id, EntityMode entityMode) at NHibernate.Impl.SessionImpl.Instantiate(IEntityPersister persister, Object id) at NHibernate.Impl.SessionImpl.Instantiate(String clazz, Object id) at NHibernate.Loader.Loader.InstanceNotYetLoaded(IDataReader dr, Int32 i, ILoadable persister, EntityKey key, LockMode lockMode, String rowIdAlias, EntityKey optionalObjectKey, Object optionalObject, IList hydratedObjects, ISessionImplementor session) at NHibernate.Loader.Loader.GetRow(IDataReader rs, ILoadable[] persisters, EntityKey[] keys, Object optionalObject, EntityKey optionalObjectKey, LockMode[] lockModes, IList hydratedObjects, ISessionImplementor session) at NHibernate.Loader.Loader.GetRowFromResultSet(IDataReader resultSet, ISessionImplementor session, QueryParameters queryParameters, LockMode[] lockModeArray, EntityKey optionalObjectKey, IList hydratedObjects, EntityKey[] keys, Boolean returnProxies) at NHibernate.Loader.Loader.DoQuery(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies) at NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies) at NHibernate.Loader.Loader.DoList(ISessionImplementor session, QueryParameters queryParameters) 10:07:46,269 [TestRunnerThread] WARN [NHibernate.Util.ADOExceptionReporter] - System.NotSupportedException: Specified method is not supported. at NHibernate.Proxy.AbstractProxyFactory.GetFieldInterceptionProxy(Object instanceToWrap) at NHibernate.Tuple.PocoInstantiator.Instantiate() at NHibernate.Tuple.PocoInstantiator.Instantiate(Object id) at NHibernate.Tuple.Entity.AbstractEntityTuplizer.Instantiate(Object id) at NHibernate.Persister.Entity.AbstractEntityPersister.Instantiate(Object id, EntityMode entityMode) at NHibernate.Impl.SessionImpl.Instantiate(IEntityPersister persister, Object id) at NHibernate.Impl.SessionImpl.Instantiate(String clazz, Object id) at NHibernate.Loader.Loader.InstanceNotYetLoaded(IDataReader dr, Int32 i, ILoadable persister, EntityKey key, LockMode lockMode, String rowIdAlias, EntityKey optionalObjectKey, Object optionalObject, IList hydratedObjects, ISessionImplementor session) at NHibernate.Loader.Loader.GetRow(IDataReader rs, ILoadable[] persisters, EntityKey[] keys, Object optionalObject, EntityKey optionalObjectKey, LockMode[] lockModes, IList hydratedObjects, ISessionImplementor session) at NHibernate.Loader.Loader.GetRowFromResultSet(IDataReader resultSet, ISessionImplementor session, QueryParameters queryParameters, LockMode[] lockModeArray, EntityKey optionalObjectKey, IList hydratedObjects, EntityKey[] keys, Boolean returnProxies) at NHibernate.Loader.Loader.DoQuery(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies) at NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies) at NHibernate.Loader.Loader.DoList(ISessionImplementor session, QueryParameters queryParameters) 10:07:46,269 [TestRunnerThread] ERROR [NHibernate.Util.ADOExceptionReporter] - Specified method is not supported. 10:07:46,270 [TestRunnerThread] DEBUG [NHibernate.AdoNet.ConnectionManager] - after autocommit 10:07:46,271 [TestRunnerThread] DEBUG [NHibernate.Impl.SessionImpl] - transaction completion 10:07:46,271 [TestRunnerThread] DEBUG [NHibernate.AdoNet.ConnectionManager] - transaction completed on session with on_close connection release mode; be sure to close the session to release ADO.Net resources! 10:07:46,280 [TestRunnerThread] DEBUG [NHibernate.Impl.SessionImpl] - closing session 10:07:46,280 [TestRunnerThread] DEBUG [NHibernate.AdoNet.AbstractBatcher] - running BatcherImpl.Dispose(true) 10:07:46,282 [TestRunnerThread] DEBUG [NHibernate.Connection.ConnectionProvider] - Closing connection 10:07:46,282 [TestRunnerThread] DEBUG [NHibernate.Impl.SessionImpl] - transaction completion 10:07:46,282 [TestRunnerThread] DEBUG [NHibernate.AdoNet.ConnectionManager] - transaction completed on session with on_close connection release mode; be sure to close the session to release ADO.Net resources! 10:07:46,284 [TestRunnerThread] DEBUG [NHibernate.Impl.SessionImpl] - [session-id=3e29ff04-f9e6-4498-b95c-2783ce545b9a] running ISession.Dispose() 10:07:46,284 [TestRunnerThread] DEBUG [NHibernate.Impl.SessionImpl] - [session-id=3e29ff04-f9e6-4498-b95c-2783ce545b9a] executing real Dispose(True)

Environment

None

Activity

Show:

Alex Zaytsev April 27, 2017 at 4:07 AM
Edited

Closing as incomplete. If wish to reopen the issue please submit a failing test case.

Jindrich Babica July 12, 2013 at 5:42 AM

Try this solution for the issue: https://groups.google.com/forum/#!msg/nhusers/pPnoPjd1nCY/WZMKxKP0tqUJ
It helped me. As same as Vitaliy I was also using Bytecode Castle proxy generator. Removing it from my configuration solved the issue. NHibernate will use its own default generator in such case.

Alex Zaytsev January 17, 2013 at 6:25 AM

Does it work in 3.3.x or master? If not please provide a test case

Vitaliy Kryvosheiev May 25, 2011 at 12:15 AM

Update:

Looks like it is not working event if 2nd level cache is off.

NHibernate version: 3.2.0.2001

Incomplete

Details

Assignee

Reporter

Labels

Components

Affects versions

Priority

Who's Looking?

Open Who's Looking?

Created May 25, 2011 at 12:10 AM
Updated April 27, 2017 at 4:12 AM
Resolved April 27, 2017 at 4:07 AM
Who's Looking?