HQL and With clause throws IndexOutOfRangeException, NH 3.3.1.4000

88 views
Skip to first unread message

Juan

unread,
Jul 20, 2012, 10:02:05 AM7/20/12
to nhu...@googlegroups.com
This post is more of a confirmation request that there are problems with HQL and With clause in the latest NH release. We are upgrading from NH 3.1.0.4000 and during the check of named queries step, in session factory creation, an IndexOutOfRange exception is thrown.
 
I narrow it down to hql queries which use the "with" clause, and have parameters. If the parameter(s) are removed (i.e, hard coded), the session factory gets build and no exceptions are thrown. We also have the dialect set to oracle9i, if we change it to oracle10g (main difference is the usage of ansi joins), the problem disappears as well
 
Sample hql showing problems:
from ProductCategoryGroup p join p.DistributionPoints as d with d.id = :distribuionPointId
Log:
09:54:44,176 [1] INFO  NHibernate.Cfg.Environment - NHibernate 3.3.1.4000 (3.3.1.4000)
...
09:54:46,729 [1] DEBUG NHibernate.Impl.SessionFactoryImpl - Checking 1 named HQL queries
09:54:46,730 [1] DEBUG NHibernate.Impl.SessionFactoryImpl - Checking named query: ProdCatByDistPoint
09:54:46,734 [1] DEBUG Engine.Query.QueryPlanCache - unable to locate HQL query plan in cache; generating (from ProductCategoryGroup p join p.DistributionPoints as d with d.id = :distribuionPointId)
09:54:46,848 [1] DEBUG Ast.ANTLR.HqlParseEngine - parse() - HQL: from ProductCategoryGroup p join p.DistributionPoints as d with d.id = :distribuionPointId
09:54:46,999 [1] DEBUG Ast.ANTLR.ErrorCounter - throwQueryException() : no errors
09:54:47,107 [1] DEBUG Ast.ANTLR.HqlSqlWalker - select << begin [level=1, statement=select]
09:54:47,135 [1] DEBUG ANTLR.Tree.FromElement - FromClause{level=1} :  ScratchPad.Model.ProductCategoryGroup (p) -> productcat0_
09:54:47,159 [1] DEBUG ANTLR.Tree.FromReferenceNode - Resolved :  p -> productcat0_.PRODUCT_CATEGORY_GROUP_ID
09:54:47,169 [1] INFO  ANTLR.Tree.FromElement - handling property dereference [ScratchPad.Model.ProductCategoryGroup (p) -> DistributionPoints (Class)]
09:54:47,177 [1] DEBUG ANTLR.Tree.DotNode - getDataType() : DistributionPoints -> NHibernate.Type.GenericSetType`1[[ScratchPad.Model.DistributionPoint](ScratchPad.Model.ProductCategoryGroup.DistributionPoints)
09:54:47,187 [1] DEBUG ANTLR.Tree.FromElementFactory - createManyToMany() : path = p.DistributionPoints role = ScratchPad.Model.ProductCategoryGroup.DistributionPoints associatedEntityName = ScratchPad.Model.DistributionPoint
09:54:47,194 [1] DEBUG ANTLR.Tree.FromElement - FromClause{level=1} :  ScratchPad.Model.DistributionPoint (d) -> distributi2_
09:54:47,197 [1] DEBUG ANTLR.Tree.FromClause - addJoinByPathMap() : p.DistributionPoints -> DISTRIBUTION_POINT distributi2_
09:54:47,198 [1] DEBUG ANTLR.Tree.DotNode - dereferenceCollection() : Created new FROM element for p.DistributionPoints : DSTRBTN_PNT_PRDCT_CTG_GRP distributi2_
09:54:47,199 [1] DEBUG ANTLR.Tree.FromReferenceNode - Resolved :  p.DistributionPoints -> .
09:54:47,247 [1] DEBUG ANTLR.Tree.FromReferenceNode - Resolved :  d -> distributi2_.DISTRIBUTION_POINT_ID
09:54:47,248 [1] INFO  ANTLR.Tree.FromElement - handling property dereference [ScratchPad.Model.DistributionPoint (d) -> id (Class)]
09:54:47,249 [1] DEBUG ANTLR.Tree.DotNode - getDataType() : id -> NHibernate.Type.Int64Type
09:54:47,250 [1] DEBUG ANTLR.Tree.FromReferenceNode - Resolved :  d.id -> distributi2_.DISTRIBUTION_POINT_ID
09:54:47,263 [1] DEBUG Ast.ANTLR.HqlSqlWalker - handleWithFragment() : ( with ( = ( distributi2_.DISTRIBUTION_POINT_ID distributi2_.DISTRIBUTION_POINT_ID id ) ? ) )
09:54:47,328 [1] DEBUG Ast.ANTLR.HqlSqlWalker - createFromJoinElement() : DSTRBTN_PNT_PRDCT_CTG_GRP distributi2_
09:54:47,331 [1] DEBUG Ast.ANTLR.HqlSqlWalker - select : finishing up [level=1, statement=select]
09:54:47,333 [1] DEBUG Ast.ANTLR.HqlSqlWalker - processQuery() : ( SELECT ( FromClause{level=1} ( PRODUCT_CATEGORY_GROUP productcat0_ DSTRBTN_PNT_PRDCT_CTG_GRP distributi2_ ) ) )
09:54:47,351 [1] DEBUG Ast.ANTLR.HqlSqlWalker - Derived SELECT clause created.
09:54:47,362 [1] DEBUG ANTLR.Util.JoinProcessor - Using FROM fragment [PRODUCT_CATEGORY_GROUP productcat0_]
09:54:47,368 [1] DEBUG ANTLR.Util.JoinProcessor - Using FROM fragment [DSTRBTN_PNT_PRDCT_CTG_GRP distributi1_, DISTRIBUTION_POINT distributi2_]
09:54:47,368 [1] DEBUG ANTLR.Util.SyntheticAndFactory - Using unprocessed WHERE-fragment [productcat0_.PRODUCT_CATEGORY_GROUP_ID=distributi1_.PRODUCT_CATEGORY_GROUP_ID and distributi1_.DISTRIBUTION_POINT_ID=distributi2_.DISTRIBUTION_POINT_ID and (distributi2_.DISTRIBUTION_POINT_ID=?)]
09:54:47,369 [1] DEBUG ANTLR.Util.SyntheticAndFactory - Using processed WHERE-fragment [productcat0_.PRODUCT_CATEGORY_GROUP_ID=distributi1_.PRODUCT_CATEGORY_GROUP_ID and distributi1_.DISTRIBUTION_POINT_ID=distributi2_.DISTRIBUTION_POINT_ID and (distributi2_.DISTRIBUTION_POINT_ID=?)]
09:54:47,370 [1] DEBUG ANTLR.Tree.QueryNode - getWhereClause() : Creating a new WHERE clause...
09:54:47,372 [1] DEBUG Ast.ANTLR.HqlSqlWalker - select >> end [level=1, statement=select]
09:54:47,373 [1] DEBUG Ast.ANTLR.ErrorCounter - throwQueryException() : no errors
09:54:47,399 [1] DEBUG Ast.ANTLR.ErrorCounter - throwQueryException() : no errors
09:54:47,400 [1] FATAL Program - Unhandled Exception
System.IndexOutOfRangeException: Index was outside the bounds of the array.
   at NHibernate.Hql.Ast.ANTLR.Tree.FromElement.RenderText(ISessionFactoryImplementor sessionFactory) in D:\Downloads\nhibernate33\nhibernate-nhibernate-core-7f3252b\src\NHibernate\Hql\Ast\ANTLR\Tree\FromElement.cs:line 347
   at NHibernate.Hql.Ast.ANTLR.SqlGenerator.Out(IASTNode n) in D:\Downloads\nhibernate33\nhibernate-nhibernate-core-7f3252b\src\NHibernate\Hql\Ast\ANTLR\SqlGenerator.cs:line 138
   at NHibernate.Hql.Ast.ANTLR.SqlGenerator.NestedFromFragment(IASTNode d, IASTNode parent) in D:\Downloads\nhibernate33\nhibernate-nhibernate-core-7f3252b\src\NHibernate\Hql\Ast\ANTLR\SqlGenerator.cs:line 261
   at NHibernate.Hql.Ast.ANTLR.SqlGenerator.tableJoin(IASTNode parent) in D:\Downloads\nhibernate33\nhibernate-nhibernate-core-7f3252b\src\NHibernate\Hql\Ast\ANTLR\Generated\SqlGenerator.cs:line 2874
   at NHibernate.Hql.Ast.ANTLR.SqlGenerator.fromTable() in D:\Downloads\nhibernate33\nhibernate-nhibernate-core-7f3252b\src\NHibernate\Hql\Ast\ANTLR\Generated\SqlGenerator.cs:line 2689
   at NHibernate.Hql.Ast.ANTLR.SqlGenerator.from() in D:\Downloads\nhibernate33\nhibernate-nhibernate-core-7f3252b\src\NHibernate\Hql\Ast\ANTLR\Generated\SqlGenerator.cs:line 2593
   at NHibernate.Hql.Ast.ANTLR.SqlGenerator.selectStatement() in D:\Downloads\nhibernate33\nhibernate-nhibernate-core-7f3252b\src\NHibernate\Hql\Ast\ANTLR\Generated\SqlGenerator.cs:line 486
   at NHibernate.Hql.Ast.ANTLR.SqlGenerator.statement() in D:\Downloads\nhibernate33\nhibernate-nhibernate-core-7f3252b\src\NHibernate\Hql\Ast\ANTLR\Generated\SqlGenerator.cs:line 407
   at NHibernate.Hql.Ast.ANTLR.HqlSqlGenerator.Generate() in D:\Downloads\nhibernate33\nhibernate-nhibernate-core-7f3252b\src\NHibernate\Hql\Ast\ANTLR\QueryTranslatorImpl.cs:line 611
   at NHibernate.Hql.Ast.ANTLR.QueryTranslatorImpl.DoCompile(IDictionary`2 replacements, Boolean shallow, String collectionRole) in D:\Downloads\nhibernate33\nhibernate-nhibernate-core-7f3252b\src\NHibernate\Hql\Ast\ANTLR\QueryTranslatorImpl.cs:line 353
   at NHibernate.Hql.Ast.ANTLR.QueryTranslatorImpl.Compile(IDictionary`2 replacements, Boolean shallow) in D:\Downloads\nhibernate33\nhibernate-nhibernate-core-7f3252b\src\NHibernate\Hql\Ast\ANTLR\QueryTranslatorImpl.cs:line 72
   at NHibernate.Hql.Ast.ANTLR.ASTQueryTranslatorFactory.CreateQueryTranslators(IASTNode ast, String queryIdentifier, String collectionRole, Boolean shallow, IDictionary`2 filters, ISessionFactoryImplementor factory) in D:\Downloads\nhibernate33\nhibernate-nhibernate-core-7f3252b\src\NHibernate\Hql\Ast\ANTLR\ASTQueryTranslatorFactory.cs:line 43
   at NHibernate.Hql.Ast.ANTLR.ASTQueryTranslatorFactory.CreateQueryTranslators(String queryString, String collectionRole, Boolean shallow, IDictionary`2 filters, ISessionFactoryImplementor factory) in D:\Downloads\nhibernate33\nhibernate-nhibernate-core-7f3252b\src\NHibernate\Hql\Ast\ANTLR\ASTQueryTranslatorFactory.cs:line 21
   at NHibernate.Engine.Query.HQLStringQueryPlan.CreateTranslators(String hql, String collectionRole, Boolean shallow, IDictionary`2 enabledFilters, ISessionFactoryImplementor factory) in D:\Downloads\nhibernate33\nhibernate-nhibernate-core-7f3252b\src\NHibernate\Engine\Query\HQLStringQueryPlan.cs:line 24
   at NHibernate.Engine.Query.HQLStringQueryPlan..ctor(String hql, String collectionRole, Boolean shallow, IDictionary`2 enabledFilters, ISessionFactoryImplementor factory) in D:\Downloads\nhibernate33\nhibernate-nhibernate-core-7f3252b\src\NHibernate\Engine\Query\HQLStringQueryPlan.cs:line 16
   at NHibernate.Engine.Query.HQLStringQueryPlan..ctor(String hql, Boolean shallow, IDictionary`2 enabledFilters, ISessionFactoryImplementor factory) in D:\Downloads\nhibernate33\nhibernate-nhibernate-core-7f3252b\src\NHibernate\Engine\Query\HQLStringQueryPlan.cs:line 10
   at NHibernate.Engine.Query.QueryPlanCache.GetHQLQueryPlan(String queryString, Boolean shallow, IDictionary`2 enabledFilters) in D:\Downloads\nhibernate33\nhibernate-nhibernate-core-7f3252b\src\NHibernate\Engine\Query\QueryPlanCache.cs:line 61
   at NHibernate.Impl.SessionFactoryImpl.CheckNamedQueries() in D:\Downloads\nhibernate33\nhibernate-nhibernate-core-7f3252b\src\NHibernate\Impl\SessionFactoryImpl.cs:line 1109
   at NHibernate.Impl.SessionFactoryImpl..ctor(Configuration cfg, IMapping mapping, Settings settings, EventListeners listeners) in D:\Downloads\nhibernate33\nhibernate-nhibernate-core-7f3252b\src\NHibernate\Impl\SessionFactoryImpl.cs:line 363
   at NHibernate.Cfg.Configuration.BuildSessionFactory() in D:\Downloads\nhibernate33\nhibernate-nhibernate-core-7f3252b\src\NHibernate\Cfg\Configuration.cs:line 1258
   at ScratchPad.Program.Main(String[] args) in D:\Home\Temp\ExtractionPerformanceTest\ScratchPad\Program.cs:line 25
 
Message has been deleted

Juan

unread,
Jul 20, 2012, 4:32:20 PM7/20/12
to nhu...@googlegroups.com
It looks like this bug fix (NH-2736) to NHibernate.Hql.Ast.ANTLR.Tree.
FromElement.RenderText() is to blame. Not sure how much more time I can spend in this code before we decide to go with plan B (rewrite hql queries), but I will try to report back if I come up with a patch.

Juan

unread,
Jul 23, 2012, 3:25:19 PM7/23/12
to nhu...@googlegroups.com
Ended up creating a JIRA ticket, NH-3228 since it is a bug easily reproducible with the core NHibernate.Test.Hql.Ast.WithFixture by using the oracle template and changing the dialect to 9i
Reply all
Reply to author
Forward
0 new messages