|
From: Andrei A. (JIRA) <nh...@gm...> - 2011-05-24 13:13:50
|
[ http://216.121.112.228/browse/NH-2734?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=21179#action_21179 ]
Andrei Alecu commented on NH-2734:
----------------------------------
Ok, bare with me for a second please:
Based on what you're saying, this shouldn't work either:
from Being b where b.class = Alien
However, someone was smart enough to add some special handling so that in this case the class name is converted to its SQL discriminator value, as I mentioned in the comments in NH-2328.
Please look at LiteralProcessor.cs line 153:
// IDENT might be the name of a class.
IQueryable queryable = _walker.SessionFactoryHelper.FindQueryableUsingImports(constant.Text);
if (isIdent && queryable != null)
{
constant.Text = queryable.DiscriminatorSQLValue;
}
*That* little fix however is unfortunately incomplete, and does not work in all cases... classes mapped as <any> do not have explicit discriminator values assigned to them, because they could be used in several mappings with several different discriminator values.
I believe the proper fix would've been to parametrize the equality for .class=? so that NullSafeSet() would be called by default, and MetaType would itself handle this scenario.
This way, the fix would be consistent for *BOTH* of these scenarios.
Please give this some thought before dismissing it as not being a bug, it is not good API design to have such terribly inconsistent behavior and consider it by design. :)
> 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
|