|
From: Andrei A. (JIRA) <nh...@gm...> - 2011-05-24 10:43:45
|
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
|
|
From: Fabio M. (JIRA) <nh...@gm...> - 2011-05-24 12:34:47
|
[ http://216.121.112.228/browse/NH-2734?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Fabio Maulo closed NH-2734.
---------------------------
Resolution: Not an Issue
The NullSafeSet is not called because you don't have something to set.
When you use a constant, in the HQL, to compare a special not existent property (as 'class' or 'id') you have to know its "secret" type/db-representation.
> 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
|
|
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
|
|
From: Fabio M. (JIRA) <nh...@gm...> - 2011-05-24 12:55:48
|
[ http://216.121.112.228/browse/NH-2734?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=21177#action_21177 ]
Fabio Maulo commented on NH-2734:
---------------------------------
Is not a bug because when you use a parameter is supposed that NH may have some way to understand how assign it.
Probably you are using meta-values... in this case the "secret" db-representation is your own representation.
Try to avoid meta-values and let us know what happen specifying a class in hql-line instead use a parameter.
> 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
|
|
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
|