-->
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: calendar casting problem
PostPosted: Mon Jan 15, 2007 7:48 am 
Newbie

Joined: Thu May 05, 2005 5:54 am
Posts: 17
Hello, i'm having problems with this query (mappings below):
Code:
select tag.id from Tag tag join tag.cm1Shift shift where cast(tag.cm1Shift.start as date) >= cast(tag.cm1Shift.finish as date)

the same query but without casts works:
Code:
select tag.id from Tag tag join tag.cm1Shift shift where tag.cm1Shift.start >= tag.cm1Shift.finish

making a query leaving casts but using the Shift entity directly works:
Code:
select shift.id from Shift shift where cast(shift.start as date) >= cast(shift.finish as date)


The stack trace does non help much.
Thank you for any help

Hibernate version:
3.2.0

Mapping documents:
Code:
class Shift {
[...]
    @Column(name="periodStart", nullable=true)
    @Temporal(TemporalType.TIMESTAMP)   
    private Calendar start;

    @Column(name="periodFinish", nullable=true)
    @Temporal(TemporalType.TIMESTAMP)   
    private Calendar finish;
[...]
}

class Tag {
[...]
    @ManyToOne(cascade=CascadeType.MERGE)
    Shift cm1Shift;
[...]
}



Full stack trace of any exception that occurs:
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.containsClassAlias(FromClause.java:247)
        at org.hibernate.hql.ast.tree.FromClause.isFromElementAlias(FromClause.java:135)
        at org.hibernate.hql.ast.HqlSqlWalker.isNonQualifiedPropertyRef(HqlSqlWalker.java:474)
        at org.hibernate.hql.antlr.HqlSqlBaseWalker.addrExpr(HqlSqlBaseWalker.java:4382)
        at org.hibernate.hql.antlr.HqlSqlBaseWalker.expr(HqlSqlBaseWalker.java:1212)
        at org.hibernate.hql.antlr.HqlSqlBaseWalker.functionCall(HqlSqlBaseWalker.java:2299)
        at org.hibernate.hql.antlr.HqlSqlBaseWalker.expr(HqlSqlBaseWalker.java:1287)
        at org.hibernate.hql.antlr.HqlSqlBaseWalker.exprOrSubquery(HqlSqlBaseWalker.java:4041)
        at org.hibernate.hql.antlr.HqlSqlBaseWalker.comparisonExpr(HqlSqlBaseWalker.java:3645)
        at org.hibernate.hql.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:1762)
        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)


Name and version of the database you are using:
postgresql 8.15

The generated SQL (show_sql=true):
No query is generated.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 16, 2007 6:03 am 
Newbie

Joined: Thu May 05, 2005 5:54 am
Posts: 17
solved by using aliases.
the query:

Code:
select tag.id from Tag tag join tag.cm1Shift shift where cast(tag.cm1Shift.start as date) >= cast(tag.cm1Shift.finish as date)


defines aliases that i do not use in the where clause. if i use them all works fine:

Code:
select tag.id from Tag tag join tag.cm1Shift shift where cast(shift.start as date) >= cast(shift.finish as date)


maybe it's a bug that an exception is thrown without any useful information (for the end user) to solve the problem???


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 16, 2007 9:45 am 
Senior
Senior

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

Looks like you found the same bug i found http://opensource.atlassian.com/projects/hibernate/browse/HHH-2159

You can manually patch the FromClause.java yourself, it is pretty simple.

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.