-->
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.  [ 5 posts ] 
Author Message
 Post subject: Bug: HQL Expressions in WHERE clauses of HQL aren't expected
PostPosted: Tue Jun 07, 2005 11:27 am 
Newbie

Joined: Tue Jun 07, 2005 10:58 am
Posts: 3
Hibernate version:
3
Quote:
This problem don't exist in Hibernate 2.


Java Bean:
Code:
package org.hibernate.bug1;
public class BaBu1_Record
{
    private int m_key;

    private double m_a;

    /**
     * @return the value A
     */
    public double getA()
    {
        return m_a;
    }

    /**
     * @param a the Value A
     */
    public void setA(double a)
    {
        m_a = a;
    }

    /**
     * @return the primary key
     */
    public int getKey()
    {
        return m_key;
    }

    /**
     * @param m_key set the primary key
     */
    private void setKey(int key)
    {
        m_key = key;
    }
}


Mapping documents:
BaBu1_Record.hbm.xml:
Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="org.hibernate.bug1">
    <class name="BaBu1_Record">
        <id name="key"><generator class="native" /></id>
        <property name="a" />
    </class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
Code:
            final String hsqlStatement = "from BaBu1_Record r where abs(r.a - :value) < 0.001";
            Query query = session.createQuery(hsqlStatement);
            query.setDouble("value", 1.0d);
            query.list();

Full stack trace of any exception that occurs:
Code:
java.lang.ClassCastException
   at org.hibernate.hql.ast.ArithmeticNode.getDataType(ArithmeticNode.java:13)
   at org.hibernate.hql.ast.SessionFactoryHelper.findFunctionReturnType(SessionFactoryHelper.java:188)
   at org.hibernate.hql.ast.MethodNode.dialectFunction(MethodNode.java:55)
   at org.hibernate.hql.ast.MethodNode.resolve(MethodNode.java:43)
   at org.hibernate.hql.ast.HqlSqlWalker.processFunction(HqlSqlWalker.java:538)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.functionCall(HqlSqlBaseWalker.java:2045)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.expr(HqlSqlBaseWalker.java:933)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.exprOrSubquery(HqlSqlBaseWalker.java:3713)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.comparisonExpr(HqlSqlBaseWalker.java:3240)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:1405)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.whereClause(HqlSqlBaseWalker.java:599)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:404)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:201)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:151)
   at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:189)
   at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:130)
   at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:83)
   at org.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:427)
   at org.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:884)
   at org.hibernate.impl.SessionImpl.list(SessionImpl.java:834)
   at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
   at org.hibernate.bug1.BaBu1_BugTest_tc.testBug1(BaBu1_BugTest_tc.java:52)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   at java.lang.reflect.Method.invoke(Unknown Source)
   at junit.framework.TestCase.runTest(TestCase.java:154)
   at junit.framework.TestCase.runBare(TestCase.java:127)
   at junit.framework.TestResult$1.protect(TestResult.java:106)
   at junit.framework.TestResult.runProtected(TestResult.java:124)
   at junit.framework.TestResult.run(TestResult.java:109)
   at junit.framework.TestCase.run(TestCase.java:118)
   at junit.framework.TestSuite.runTest(TestSuite.java:208)
   at junit.framework.TestSuite.run(TestSuite.java:203)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:474)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:342)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:194)


Name and version of the database you are using:
HSQLDB and Oracle 9.2.0.6. The problem is a bug in Hibernate and so
independant of the used database.

The generated SQL (show_sql=true):
There is no generated SQL.

Can anybody confirm this Hibernate bug! Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 07, 2005 11:47 am 
Expert
Expert

Joined: Wed Apr 06, 2005 5:03 pm
Posts: 273
Location: Salt Lake City, Utah, USA
I ran into this problem while using abs in a similar way. in my case the values were floats, and i had to use cast() to work around it. here's what my abs() turned into:

Code:
abs(cast(o.difficulty as float) - cast(:maxdiff as float))


it seemed like a bug to me, too, since cast() is supposed to follow EJB3.0 specs and those say any numeric type is allowed. but i never followed up on it because i found the workaround.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 07, 2005 12:07 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Fixed in CVS


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 08, 2005 1:14 am 
Newbie

Joined: Tue Jun 07, 2005 10:58 am
Posts: 3
nathanmoon wrote:
I ran into this problem while using abs in a similar way. in my case the values were floats, and i had to use cast() to work around it. here's what my abs() turned into:

abs(cast(o.difficulty as float) - cast(:maxdiff as float))

it seemed like a bug to me, too, since cast() is supposed to follow EJB3.0 specs and those say any numeric type is allowed. but i never followed up on it because i found the workaround.


Thanks for this workaround!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 08, 2005 1:17 am 
Newbie

Joined: Tue Jun 07, 2005 10:58 am
Posts: 3
gavin wrote:
Fixed in CVS


Thanks for this information and your work in the scope of this project!


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