From: Andrei A. (JIRA) <nh...@gm...> - 2011-05-24 12:47:51
|
[ http://216.121.112.228/browse/NH-2734?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=21176#action_21176 ] Andrei Alecu commented on NH-2734: ---------------------------------- I don't think that's right Fabio. See the test in UnionSubclassFixture.cs. Assert.AreEqual(1, s.CreateQuery("from Being b where b.class = Alien").List().Count); This works properly for classes mapped as a hierarchy, and you don't need to use any secret type. Not being able to use the same query on <any> mappings is not consistent and I don't see it documented anywhere, if you can point me towards documentation it would be great. Anyway, something working as a parameter, but not as a literal in a HQL query does not make sense to me. I would still consider this to be a major bug. Also note that this works: var boxes = s.CreateQuery("from ToyBox t where t.Shape.class = 2").List<ToyBox>(); But this does not work: var boxes = s.CreateQuery("from ToyBox t where t.Shape.class = :clazz") .SetParameter("clazz", 2) .List<ToyBox>(); I don't see how this inconsistent behavior is not considered a bug. The only problem is, trying to come up with a fix is probably non trivial. I'm not sure if Hibernate is affected or not, or if they fixed this already. > HQL .class query on <any> mapping does not work > ----------------------------------------------- > > Key: NH-2734 > URL: http://216.121.112.228/browse/NH-2734 > Project: NHibernate > Issue Type: Bug > Components: Core > Affects Versions: 3.2.0Beta1 > Reporter: Andrei Alecu > Priority: Major > > Consider the test in trunk for NH-2328. > Modifying it to do this does not work: > var boxes = s.CreateQuery("from ToyBox t where t.Shape.class = Square") > .List<ToyBox>(); > The error is: > System.NullReferenceException : Object reference not set to an instance of an object. > at NHibernate.Hql.Ast.ANTLR.SessionFactoryHelperExtensions.FindSQLFunction(String functionName) in SessionFactoryHelperExtensions.cs: line 45 > at NHibernate.Hql.Ast.ANTLR.Tree.IdentNode.get_DataType() in IdentNode.cs: line 41 > at NHibernate.Hql.Ast.ANTLR.Tree.BinaryLogicOperatorNode.ExtractDataType(IASTNode operand) in BinaryLogicOperatorNode.cs: line 244 > at NHibernate.Hql.Ast.ANTLR.Tree.BinaryLogicOperatorNode.Initialize() in BinaryLogicOperatorNode.cs: line 50 > at NHibernate.Hql.Ast.ANTLR.HqlSqlWalker.PrepareLogicOperator(IASTNode operatorNode) in HqlSqlWalker.cs: line 786 > at NHibernate.Hql.Ast.ANTLR.HqlSqlWalker.comparisonExpr() in HqlSqlWalker.cs: line 6239 > at NHibernate.Hql.Ast.ANTLR.HqlSqlWalker.logicalExpr() in HqlSqlWalker.cs: line 5228 > at NHibernate.Hql.Ast.ANTLR.HqlSqlWalker.whereClause() in HqlSqlWalker.cs: line 4952 > at NHibernate.Hql.Ast.ANTLR.HqlSqlWalker.unionedQuery() in HqlSqlWalker.cs: line 1706 > at NHibernate.Hql.Ast.ANTLR.HqlSqlWalker.query() in HqlSqlWalker.cs: line 1514 > at NHibernate.Hql.Ast.ANTLR.HqlSqlWalker.selectStatement() in HqlSqlWalker.cs: line 540 > at NHibernate.Hql.Ast.ANTLR.HqlSqlWalker.statement() in HqlSqlWalker.cs: line 439 > at NHibernate.Hql.Ast.ANTLR.HqlSqlTranslator.Translate() in QueryTranslatorImpl.cs: line 590 > at NHibernate.Hql.Ast.ANTLR.QueryTranslatorImpl.Analyze(String collectionRole) in QueryTranslatorImpl.cs: line 449 > at NHibernate.Hql.Ast.ANTLR.QueryTranslatorImpl.DoCompile(IDictionary`2 replacements, Boolean shallow, String collectionRole) in QueryTranslatorImpl.cs: line 354 > at NHibernate.Hql.Ast.ANTLR.QueryTranslatorImpl.Compile(IDictionary`2 replacements, Boolean shallow) in QueryTranslatorImpl.cs: line 71 > at NHibernate.Hql.Ast.ANTLR.ASTQueryTranslatorFactory.CreateQueryTranslators(IASTNode ast, String queryIdentifier, String collectionRole, Boolean shallow, IDictionary`2 filters, ISessionFactoryImplementor factory) in ASTQueryTranslatorFactory.cs: line 43 > at NHibernate.Hql.Ast.ANTLR.ASTQueryTranslatorFactory.CreateQueryTranslators(String queryString, String collectionRole, Boolean shallow, IDictionary`2 filters, ISessionFactoryImplementor factory) in ASTQueryTranslatorFactory.cs: line 21 > at NHibernate.Engine.Query.HQLStringQueryPlan.CreateTranslators(String hql, String collectionRole, Boolean shallow, IDictionary`2 enabledFilters, ISessionFactoryImplementor factory) in HQLStringQueryPlan.cs: line 24 > at NHibernate.Engine.Query.HQLStringQueryPlan..ctor(String hql, String collectionRole, Boolean shallow, IDictionary`2 enabledFilters, ISessionFactoryImplementor factory) in HQLStringQueryPlan.cs: line 16 > at NHibernate.Engine.Query.HQLStringQueryPlan..ctor(String hql, Boolean shallow, IDictionary`2 enabledFilters, ISessionFactoryImplementor factory) in HQLStringQueryPlan.cs: line 10 > at NHibernate.Engine.Query.QueryPlanCache.GetHQLQueryPlan(String queryString, Boolean shallow, IDictionary`2 enabledFilters) in QueryPlanCache.cs: line 61 > at NHibernate.Impl.AbstractSessionImpl.GetHQLQueryPlan(String query, Boolean shallow) in AbstractSessionImpl.cs: line 304 > at NHibernate.Impl.AbstractSessionImpl.CreateQuery(String queryString) in AbstractSessionImpl.cs: line 283 > at NHibernate.Test.NHSpecificTest.NH2328.Fixture.AnyIs_HqlRequiresNumberIn() in Fixture.cs: line 80 > However, explicitly using a parameter works properly: > var boxes = s.CreateQuery("from ToyBox t where t.Shape.class = :clazz") > .SetParameter("clazz", typeof(Square).FullName).List<ToyBox>(); > Upon further inspection, it works because the implementation calls NullSafeSet() on MetaType while setting the parameter. If the type is specified inline, NullSafeSet isn't called. > I believe the proper fix here would be for the query parser to extract what's after = here and pass it in as a parameter, if possible, so that NullSafeSet() is called. It might involve changes to the grammar files, I'm not sure. > Fixing this bug in the HQL parser should also fix NH-2328. -- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://216.121.112.228/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira |