public object Load(object id, object optionalObject, ISessionImplementor session) { if (log.IsDebugEnabled) { log.Debug(string.Format("loading entity: {0} using named query: {1}", persister.EntityName, queryName)); } AbstractQueryImpl query = (AbstractQueryImpl)session.GetNamedQuery(queryName); if (query.HasNamedParameters) { query.SetParameter(query.NamedParameters[0], id, persister.IdentifierType); } else { query.SetParameter(0, id, persister.IdentifierType); } query.SetOptionalId(id); query.SetOptionalEntityName(persister.EntityName); query.SetOptionalObject(optionalObject); query.SetFlushMode(FlushMode.Never); query.List(); // now look up the object we are really interested in! // (this lets us correctly handle proxies and multi-row // or multi-column queries) return(session.PersistenceContext.GetEntity(new EntityKey(id, persister, session.EntityMode))); }
public async Task <object> LoadAsync(object id, object optionalObject, ISessionImplementor session, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); if (log.IsDebugEnabled) { log.Debug(string.Format("loading entity: {0} using named query: {1}", persister.EntityName, queryName)); } AbstractQueryImpl query = (AbstractQueryImpl)session.GetNamedQuery(queryName); if (query.HasNamedParameters) { query.SetParameter(query.NamedParameters[0], id, persister.IdentifierType); } else { query.SetParameter(0, id, persister.IdentifierType); } query.SetOptionalId(id); query.SetOptionalEntityName(persister.EntityName); query.SetOptionalObject(optionalObject); query.SetFlushMode(FlushMode.Manual); await(query.ListAsync(cancellationToken)).ConfigureAwait(false); // now look up the object we are really interested in! // (this lets us correctly handle proxies and multi-row // or multi-column queries) return(session.PersistenceContext.GetEntity(session.GenerateEntityKey(id, persister))); }