-->
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.  [ 4 posts ] 
Author Message
 Post subject: createQuery throws parse exception if it contains 'size'
PostPosted: Mon May 15, 2006 12:33 pm 
Regular
Regular

Joined: Thu Jan 29, 2004 10:34 am
Posts: 52
Location: Austin, TX
having a field called 'size' on an object (and in an HQL statement) seems to cause a parsing breakdown. is it a reserved word? as in the exception it happens DotNode while getting the columns. should i debug this or is it a known problem (steveE?)

Hibernate version:3.1.3

Full stack trace of any exception that occurs:
Code:
java.lang.StringIndexOutOfBoundsException: String index out of range: -5
   at java.lang.String.substring(String.java:1768)
   at java.lang.String.substring(String.java:1735)
   at org.hibernate.hql.CollectionSubqueryFactory.createCollectionSubquery(CollectionSubqueryFactory.java:32)
   at org.hibernate.hql.ast.tree.FromElementType.toColumns(FromElementType.java:300)
   at org.hibernate.hql.ast.tree.FromElementType.toColumns(FromElementType.java:290)
   at org.hibernate.hql.ast.tree.FromElement.toColumns(FromElement.java:376)
   at org.hibernate.hql.ast.tree.DotNode.getColumns(DotNode.java:97)
   at org.hibernate.hql.ast.tree.DotNode.initText(DotNode.java:210)
   at org.hibernate.hql.ast.tree.DotNode.resolve(DotNode.java:204)
   at org.hibernate.hql.ast.tree.FromReferenceNode.resolve(FromReferenceNode.java:94)
   at org.hibernate.hql.ast.tree.FromReferenceNode.resolve(FromReferenceNode.java:90)
   at org.hibernate.hql.ast.HqlSqlWalker.resolve(HqlSqlWalker.java:725)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.expr(HqlSqlBaseWalker.java:1215)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.exprOrSubquery(HqlSqlBaseWalker.java:4032)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.comparisonExpr(HqlSqlBaseWalker.java:3638)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:1758)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:1686)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.whereClause(HqlSqlBaseWalker.java:776)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:577)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:281)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:229)
   at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:218)
   at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:158)
   at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:109)
   at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:75)
   at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:54)
   at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:71)
   at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:133)
   at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:112)
   at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1583)


Name and version of the database you are using: MSSQL

The generated SQL (show_sql=true): Well this fails in antlr so no sql is produced yet. this is well formed HQL. the only issue is the 'size' attribute on the last line. i changed my pojo to getSize() to getStorageSize() and it starts work fine again.
Code:
SELECT DISTINCT root.deviceId
FROM ConfigurationModel AS root
   JOIN root.managedElement AS managedElement_74
   JOIN managedElement_74.chassis AS chassis_75
   JOIN chassis_75.fileStorageLocations AS fileStorageLocations_76
WHERE (root.latest = 1 AND root.objectState = '0') AND ((fileStorageLocations_73.size >= '2288'))


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 17, 2006 3:17 pm 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
It looks like it collides with function size for collections
http://www.hibernate.org/hib_docs/v3/re ... xpressions

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 17, 2006 7:06 pm 
Regular
Regular

Joined: Thu Jan 29, 2004 10:34 am
Posts: 52
Location: Austin, TX
didn't debug far enough but that's what i suspected. this is because the following usage works just fine:
Code:
SELECT DISTINCT root.deviceId
FROM ConfigurationModel AS root
   JOIN root.managedElement AS managedElement_74
   JOIN managedElement_74.chassis AS chassis_75
   JOIN chassis_75.memory AS memory_76
WHERE (root.latest = 1 AND root.objectState = '0') AND ((memory_76.size >= 256000))


since chassis->memory is many-to-one wheras in the previous example above chassis->fileStorageLocations is one-to-many ... and hence the failure

i think the parser could differentiate between 'size' - an attribute and 'size()' - a function


Last edited by ravi on Thu May 18, 2006 12:35 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Wed May 17, 2006 7:07 pm 
Regular
Regular

Joined: Thu Jan 29, 2004 10:34 am
Posts: 52
Location: Austin, TX
----------------------------


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

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.