-->
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.  [ 3 posts ] 
Author Message
 Post subject: CrazyJPARequirements
PostPosted: Tue Nov 21, 2006 10:32 am 
Newbie

Joined: Tue Nov 21, 2006 8:59 am
Posts: 1
I have this really crazy problem with the JPA Query Language. The basic structure on the database is as follows:
Code:
   Vehicle --(1-to-many)-->
           RatePeriod --(1-to-many) -->
               RateValue 


RateValue has a field called "minDays" which determines the first rate value applicable for a specific duration (eg 12 days, 14 days, 31 days, 99 days ), the idea is to select the max value available, (for example if days==16 then minDays should be 14, etc.. ). At the moment I use a sub-query to restrict the values for a specific period.

Query (1) works fine, but the moment I add the sub query to restrict the values per period on query (2) I get this huge completely insane stack trace. (See stack trace). I spend a whole day going through the JPA specification, and the hibernate documents. I still cannot see what is wrong the query statement. I strongly believe that a "NullPointerExcption" inherently indicates a problem in the Hibernate library.

These exceptions only started after I upgraded from 3.2.0.cr4 to 3.2.0.GA.

Query-1
Code:
SELECT
    v.period.vehicle,
    v.period.rate,
    max(v.value)
FROM
    RateValue AS v
WHERE
    v.period.startDate        <= :startDate
    AND v.period.endDate           > :startDate
    AND v.period.rate.code         = :rateCode
    AND v.period.account.id        = :accountId
    AND v.period.loyaltyProgram    = :isLoyaltyProgram
GROUP BY
    v.period.vehicle,
    v.period.rate


Query-2
Code:
SELECT
    v.period.vehicle,
    v.period.rate,
    max(v.value)
FROM
    RateValue AS v
WHERE
    v.minDays = ( select max( t.minDays ) from RateValue as t where t.period = v.period AND t.minDays <= :days )
    AND v.period.startDate        <= :startDate
    AND v.period.endDate           > :startDate
    AND v.period.rate.code         = :rateCode
    AND v.period.account.id        = :accountId
    AND v.period.loyaltyProgram    = :isLoyaltyProgram
GROUP BY
    v.period.vehicle,
    v.period.rate


Stack trace
Code:
Exception in thread "main" java.lang.NullPointerException
   at org.hibernate.hql.ast.tree.FromClause.findIntendedAliasedFromElementBasedOnCrazyJPARequirements(FromClause.java:120)
   at org.hibernate.hql.ast.tree.FromClause.getFromElement(FromClause.java:107)
   at org.hibernate.hql.ast.tree.FromElementFactory.addFromElement(FromElementFactory.java:81)
   at org.hibernate.hql.ast.tree.FromClause.addFromElement(FromClause.java:70)
   at org.hibernate.hql.ast.HqlSqlWalker.createFromElement(HqlSqlWalker.java:265)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:3056)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:2945)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:688)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:544)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.collectionFunctionOrSubselect(HqlSqlBaseWalker.java:4253)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.inRhs(HqlSqlBaseWalker.java:4161)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.comparisonExpr(HqlSqlBaseWalker.java:3842)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:1762)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:1690)
   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:228)
   at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:160)
   at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:111)
   at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:77)
   at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:56)
   at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:72)
   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:1623)
   at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:92)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 23, 2006 3:54 am 
Senior
Senior

Joined: Tue Jul 25, 2006 9:05 am
Posts: 163
Location: Stuttgart/Karlsruhe, Germany
Hi,

I also had this, and submitted a JIRA issue for it http://opensource.atlassian.com/projects/hibernate/browse/HHH-2159 basically you will have to modify the source code if you want to get it working with 3.2.0GA, but i spoke with Max at JBoss world and he recommended upgrading to version 3.2.1GA.

I plan test 3.2.1 later on today.


Cheers,

Andy

_________________
Rules are only there to be broken


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 23, 2006 5:31 am 
Senior
Senior

Joined: Tue Jul 25, 2006 9:05 am
Posts: 163
Location: Stuttgart/Karlsruhe, Germany
The bug still exists in 3.2.1GA, so if you want to use a GA release you will have to modify the source code (very minor modification) to stop null values being added to the map in the first place.

Cheers,

Andy

_________________
Rules are only there to be broken


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.