-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 posts ] 
Author Message
 Post subject: Invalid Column Name, Criteria Query
PostPosted: Mon Apr 30, 2007 6:41 pm 
Newbie

Joined: Mon Apr 30, 2007 6:17 pm
Posts: 14
My criteria query is throwing a SqlException "Invalid Column Name". Here's the code that creates the criteria:

Code:
DetachedCriteria criteria = DetachedCriteria.For(typeof(OrderRequest));
criteria.Add(Expression.In("Status", (IList)Statuses));
criteria.SetProjection(Projections.ProjectionList()
                .Add(Projections.Property("Id"), "Id")
                .Add(Projections.Property("Status"), "Status"));

And here is the resulting SQL:

Code:
SELECT this_.OrderRequestID as y0_, this_.StatusCode as y1_ FROM OrderRequest this_ WHERE y1_ in (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13)

SQL Server is complaining that there is no column named "y1_" when it evaluates the WHERE clause. True there is not. If I manually change "y1_" to "StatusCode" SQL Server likes it fine. If I remove the Projection for StatusCode, it works fine because NHibernate does not try to use the alias in the WHERE clause.

I am using 1.2 RC2

This seems like a bug in NHibernate. Any ideas?

Here's the stack trace:

Code:
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
at System.Data.SqlClient.SqlDataReader.ConsumeMetaData()
at System.Data.SqlClient.SqlDataReader.get_MetaData()
at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader()
at NHibernate.Impl.BatcherImpl.ExecuteReader(IDbCommand cmd)
at NHibernate.Loader.Loader.GetResultSet(IDbCommand st, RowSelection selection, ISessionImplementor session)
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)
--- End of inner exception stack trace ---
at NHibernate.Loader.Loader.DoList(ISessionImplementor session, QueryParameters queryParameters)
at NHibernate.Loader.Loader.ListIgnoreQueryCache(ISessionImplementor session, QueryParameters queryParameters)
at NHibernate.Loader.Loader.List(ISessionImplementor session, QueryParameters queryParameters, ISet querySpaces, IType[] resultTypes)
at NHibernate.Loader.Criteria.CriteriaLoader.List(ISessionImplementor session)
at NHibernate.Impl.SessionImpl.Find(CriteriaImpl criteria, IList results)
at NHibernate.Impl.SessionImpl.Find[T](CriteriaImpl criteria)
at NHibernate.Impl.CriteriaImpl.List[T]()
at Maestro.Persistence.EntityDataGateway.GetCollection[T](ISearchCriteria searchCriteria) in C:\wush\Maestro\src\Maestro.Core\Maestro.Persistence\EntityDataGateway.cs:line 684
at Maestro.Domain.OrderRequestRepository.GetOrderRequestDtos(OrderRequestCriteria criteria)
at Maestro.OrderProcessMonitor.Controllers.OrderRequestsController.List()


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 24, 2007 6:38 pm 
Newbie

Joined: Mon Apr 30, 2007 6:17 pm
Posts: 14
Gee, I hope I don't irritate anybody by bumping this up. I feel confident this is a bug. I beleive it's exactly the same as this bug in Hibernate, which has been fixed last month:
http://opensource.atlassian.com/project ... se/HHH-817

I tried to look in JIRA for NHib to see if there anything reported for this, but it seems the site is down (temporarily?).

By the way, a couple of additional facts. First, I am using SQL Server 2005. Second, the reason this is important to me (and probably will be to others) is that I want to use the wonderful results transformer feature to tranform results to a Dto class, which requires using aliases in Projections.

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 30, 2007 2:20 pm 
Newbie

Joined: Wed May 30, 2007 2:18 pm
Posts: 14
I am now encountering this problem. The hack to ensure that the alias is not the same as the actual name works. But I hope this problem is resolved.

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 30, 2007 3:03 pm 
Newbie

Joined: Wed May 30, 2007 2:18 pm
Posts: 14
Looking at the patch for http://opensource.atlassian.com/projects/hibernate/browse/HHH-817, I was able to patch NHibernate to fix the same issue.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 30, 2007 5:15 pm 
Newbie

Joined: Wed May 30, 2007 2:18 pm
Posts: 14
Created jira issue with patch on this issue.
http://jira.nhibernate.org/browse/NH-1023


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 30, 2007 7:27 pm 
Newbie

Joined: Mon Apr 30, 2007 6:17 pm
Posts: 14
crimsondr, Awesome, thanks a bunch! I'll give it a whirl.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 01, 2007 2:36 am 
Beginner
Beginner

Joined: Thu Nov 03, 2005 1:52 am
Posts: 21
My problem could be related. It didn't work at the line commented out. Any comments from experts? thanks a lot.

Code:
           
            ICriteria objCriteria = BuildOrderCriteria(searchCriteria);
            objCriteria= objCriteria
                .CreateAlias("OrderItems", "OrderItem")
                .CreateAlias("OrderItem.Product", "Product")
                .SetProjection(Projections.ProjectionList()
                                   .Add(Projections.GroupProperty("Product.Id").As("Id"))
                                   .Add(Projections.GroupProperty("Product.ProductName").As("ProductName"))
                                   .Add(Projections.Sum("OrderItem.Quantity").As("TotalOrdered")));

            return objCriteria
                //Todo: Not working here
                //.AddOrder(NOrder.Desc("TotalOrdered"))
                .SetFirstResult(firstItemIndex)
                .SetMaxResults(pageSize)
                .SetResultTransformer(Transformers.AliasToBean(typeof (TopProductDTO)))
               
                .List<TopProductDTO>();


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 01, 2007 8:35 am 
Newbie

Joined: Wed May 30, 2007 2:18 pm
Posts: 14
I'm doing the sort a little differently but I don't think it matters...
Code:
criteria.AddOrder(new Order(sortColumn, sortAscending));

This code works for me on my patched version, but I don't know about the release version as I am not using it anymore.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.