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.  [ 1 post ] 
Author Message
 Post subject: Subquery with a date is causing error
PostPosted: Sat Feb 07, 2009 8:15 pm 
Newbie

Joined: Sat Feb 07, 2009 8:06 pm
Posts: 1
Hibernate version: 2.0.1.4000

Mapping documents:

Code between sessionFactory.openSession() and session.close():

DetachedCriteria maxEffectiveDate = DetachedCriteria.For(typeof(MileageRate), "M2")
.SetProjection(Projections.Max("EffectiveDate"))
.Add(Expression.Lt("EffectiveDate",DateTime.Today))
.Add(Expression.EqProperty("M1.EffectiveDate", "M2.EffectiveDate"));


ICriteria criteria = Session.CreateCriteria(typeof(MileageRate), "M1")
.Add(Subqueries.Eq("EffectiveDate",maxEffectiveDate));



Full stack trace of any exception that occurs:
$exception {NHibernate.ADOException: could not execute query
[ SELECT this_.MileageRateID as MileageR1_6_0_, this_.Rate as Rate6_0_, this_.DateCreated as DateCrea3_6_0_, this_.Description as Descript4_6_0_, this_.HostingPartnerID as HostingP5_6_0_, this_.EffectiveDate as Effectiv6_6_0_ FROM MileageRates this_ WHERE ? = (SELECT max(this_0_.EffectiveDate) as y0_ FROM MileageRates this_0_ WHERE this_0_.EffectiveDate < ? and this_.EffectiveDate = this_0_.EffectiveDate) ]
Positional parameters: #0>EffectiveDate #0>2/7/2009 12:00:00 AM
[SQL: SELECT this_.MileageRateID as MileageR1_6_0_, this_.Rate as Rate6_0_, this_.DateCreated as DateCrea3_6_0_, this_.Description as Descript4_6_0_, this_.HostingPartnerID as HostingP5_6_0_, this_.EffectiveDate as Effectiv6_6_0_ FROM MileageRates this_ WHERE ? = (SELECT max(this_0_.EffectiveDate) as y0_ FROM MileageRates this_0_ WHERE this_0_.EffectiveDate < ? and this_.EffectiveDate = this_0_.EffectiveDate)] ---> System.InvalidCastException: Specified cast is not valid.
at NHibernate.Type.DateTimeType.Set(IDbCommand st, Object value, Int32 index)
at NHibernate.Type.NullableType.NullSafeSet(IDbCommand cmd, Object value, Int32 index)
at NHibernate.Type.NullableType.NullSafeSet(IDbCommand st, Object value, Int32 index, ISessionImplementor session)
at NHibernate.Loader.Loader.BindPositionalParameters(IDbCommand st, QueryParameters queryParameters, Int32 start, ISessionImplementor session)
at NHibernate.Loader.Loader.PrepareQueryCommand(QueryParameters parameters, Boolean scroll, 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`1 querySpaces, IType[] resultTypes)
at NHibernate.Loader.Criteria.CriteriaLoader.List(ISessionImplementor session)
at NHibernate.Impl.SessionImpl.List(CriteriaImpl criteria, IList results)
at NHibernate.Impl.CriteriaImpl.List(IList results)
at NHibernate.Impl.CriteriaImpl.List[T]()
at Oncoor.Data.Expense.ExpenseReportRepository.GetCurrentMileageRate(Int32 hostingPartnerID) in D:\dev\Oncoor\app\Oncoor.Data\Expense\ExpenseReportRepository.cs:line 51
at Oncoor.Web.Controllers.Expense.ExpenseReportsController.AddLine(ExpenseLine expenseLine) in D:\dev\Oncoor\app\Oncoor.Web.Controllers\Expense\ExpenseReportsController.cs:line 103
at lambda_method(ExecutionScope , ControllerBase , Object[] )
at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)
at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClassa.<InvokeActionMethodWithFilters>b__7()
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation)} System.Exception {NHibernate.ADOException}



Name and version of the database you are using:
SQL Server 2005


The generated SQL (show_sql=true):
SELECT this_.MileageRateID as MileageR1_6_0_,
this_.Rate as Rate6_0_, this_.DateCreated as DateCrea3_6_0_,
this_.Description as Descript4_6_0_,
this_.HostingPartnerID as HostingP5_6_0_,
this_.EffectiveDate as Effectiv6_6_0_

FROM MileageRates this_ WHERE ? = (SELECT max(this_0_.EffectiveDate) as y0_ FROM MileageRates this_0_ WHERE this_0_.EffectiveDate < ? and this_.EffectiveDate = this_0_.EffectiveDate) ]
Positional parameters: #0>EffectiveDate #0>2/7/2009 12:00:00 AM


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

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.