I updated my NHibernate and Castle libraries and have gotten further. The ResultTransformer is being picked up now, but an object reference exception is being thrown. Here is the call stack: at NHibernate.Transform.AliasToBeanResultTransformer.TransformTuple (Object[] tuple, String[] aliases) in c:\Utilities\NHibernate\Trunk\src \NHibernate\Transform\AliasToBeanResultTransformer.cs: line 55 at NHibernate.Hql.HolderInstantiator.Instantiate(Object[] row) in c: \Utilities\NHibernate\Trunk\src\NHibernate\Hql\HolderInstantiator.cs: line 79 at NHibernate.Impl.MultiQueryImpl.GetResultList(IList results) in MultiQueryImpl.cs: line 411 at NHibernate.Impl.MultiQueryImpl.ListIgnoreQueryCache() in MultiQueryImpl.cs: line 676 at NHibernate.Impl.MultiQueryImpl.List() in MultiQueryImpl.cs: line 364 at YABE.Infrastructure.DataAccess.PostRepository.FetchAll(Int32 pageIndex, Int32 pageSize) in PostRepository.cs: line 68 at IPostRepositoryProxyd4cac14aaf5d41c5a17b609bc130ccc2.InvocationFetchAll_2.InvokeMethodOnTarget () at Castle.DynamicProxy.AbstractInvocation.Proceed() at Castle.Facilities.AutomaticTransactionManagement.TransactionInterceptor.Intercept (IInvocation invocation) at Castle.DynamicProxy.AbstractInvocation.Proceed() at IPostRepositoryProxyd4cac14aaf5d41c5a17b609bc130ccc2.FetchAll(Int32 pageIndex, Int32 pageSize)
I dug into the AliasToBeanResultTransformers and the aliases parameter is null and thereby causing the exception to be thrown. Should this be classified as a bug? I also tried it with the AliasToBeanConstructorResultTransformer and have it working successfully. Having to setup the ConstructorInfo is a bit of a pain though. Now that the ResultTransformer is being applied, I could probably create a custom transformer for each dto, and that would simplify it a bit. Thanks, Joe On Jan 18, 1:57 pm, Joe <[email protected]> wrote: > I tried that with: > > query.Add(session.CreateQuery(hql) > .SetMaxResults(pageSize) > .SetFirstResult(pageIndex) > .SetResultTransformer(new > AliasToBeanResultTransformer(typeof(PostSummary)))) > .Add(session.CreateQuery("select count(*) from > PostEntity")); > > and > > query.Add(session.CreateQuery(hql) > .SetMaxResults(pageSize) > .SetFirstResult(pageIndex) > .SetResultTransformer > (Transformers.AliasToBean(typeof(PostSummary)))) > .Add(session.CreateQuery("select count(*) from > PostEntity")); > > and I still get the same results. > > When I am looking at item[0] in the locals window, the following is > displayed: > > - [0] {object[2]} object {object[]} > [0] 1073 object {int} > [1] "Test" object {string} > > Thanks, > Joe > > On Jan 18, 12:25 pm, "Gustavo Ringel" <[email protected]> > wrote: > > > In a regular query you should use SetResultTransformer, i didn't work with > > multiquery, but i'm sure if it is possible, you should use > > SetResultTransformer anyway. > > > Gustavo. > > > On Sun, Jan 18, 2009 at 8:12 PM, Joe <[email protected]> wrote: > > > > I am trying to get a subset of data and a total records count with > > > multiquery and a custom DTO. My problem is that when the results are > > > returned they come back as object[] and not my DTO. I can get it to > > > work using a mapped object, but not the DTO that is imported. > > > > Here is some code: > > > var hql = "select new PostSummary(p.Id, p.Title) from PostEntity p > > > order by p.DateCreated asc"; > > > using (var session = sessionManager.OpenSession()) > > > { > > > var query = session.CreateMultiQuery(); > > > > query.Add(session.CreateQuery(hql) > > > .SetMaxResults(pageSize) > > > .SetFirstResult(pageIndex)) > > > .Add(session.CreateQuery("select count(*) from > > > PostEntity")); > > > > var results = query.List(); > > > > var items = (IList) results[0]; > > > var count = (IList) results[1]; > > > } > > > > public class PostSummary > > > { > > > public int PostId { get; set; } > > > public string Title { get; set; } > > > > public PostSummary(int id, string title) > > > { > > > PostId = id; > > > Title = title; > > > } > > > } > > > > <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" > > > assembly="YABE.Domain" namespace="YABE.Domain.Model"> > > > <import class="PostSummary" /> > > > </hibernate-mapping> > > > > I am trying to get a list of PostSummary in the first resultset, but I > > > keep getting a list of object[]. > > > > What am I doing wrong? > > > > Thanks, > > > Joe- Hide quoted text - > > > - Show quoted text - --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
