Problem with float property as query parameter in JPA

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Problem with float property as query parameter in JPA

chawax
Hi,

I use HSQLDB 1.8.0.10 with Hibernate 3.2.6.ga as JPA implementation.
But I encounter a strange problem : I have a query that has a where clause on a float property, I set the value for this property with a query parameter ... but it never returns any result, while it should !

My query is as following :

select v from ElementValue v where v.floatValue = :floatValue

floatValue field is defined as following in my EJB entity :

    @javax.persistence.Column(name = "FLOAT_VALUE_", insertable = true, updatable = true)
    public java.lang.Float getFloatValue()
    {
        return floatValue;
    }

When running unit tests, this query returns no result.
But when running the corresponding SQL query, it works well !
I tried different HQL queries in Hibernate console to understand what happens :
   
"select v from ElementValue v where v.floatValue = 3.14" => it works
"select v from ElementValue v where v.floatValue = :floatValue " floatValue query parameter has float Java type => no result
"select v from ElementValue v where v.floatValue = :floatValue " floatValue query parameter has double Java type => it works !

So it looks like there is a problem with type mapping for float query parameters.
I had a look on Hibernate HSQL dialect and float Java type is mapped to FLOAT type.
I also had a look on HSQL driver and I could see no problem neither.

Anyone encountered this problem ?
Anyone has an idea where it could come from (and a way to workaround it) ?
Is it a known problem with JDBC driver ? With Hibernate dialect ?

Thanks in advance,

Olivier

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Hsqldb-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/hsqldb-user
Reply | Threaded
Open this post in threaded view
|

Re: Problem with float property as query parameter in JPA

Fred Toussi-2
Java float is not used in HSQLDB. Only double is used internally. You should perhaps define your tables and other definitions using DOUBLE.
 
Fred
----- Original Message -----
Sent: 06 November 2008 13:17
Subject: [Hsqldb-user] Problem with float property as query parameter in JPA

Hi,

I use HSQLDB 1.8.0.10 with Hibernate 3.2.6.ga as JPA implementation.
But I encounter a strange problem : I have a query that has a where clause on a float property, I set the value for this property with a query parameter ... but it never returns any result, while it should !

My query is as following :

select v from ElementValue v where v.floatValue = :floatValue

floatValue field is defined as following in my EJB entity :

    @javax.persistence.Column(name = "FLOAT_VALUE_", insertable = true, updatable = true)
    public java.lang.Float getFloatValue()
    {
        return floatValue;
    }

When running unit tests, this query returns no result.
But when running the corresponding SQL query, it works well !
I tried different HQL queries in Hibernate console to understand what happens :
   
"select v from ElementValue v where v.floatValue = 3.14" => it works
"select v from ElementValue v where v.floatValue = :floatValue " floatValue query parameter has float Java type => no result
"select v from ElementValue v where v.floatValue = :floatValue " floatValue query parameter has double Java type => it works !

So it looks like there is a problem with type mapping for float query parameters.
I had a look on Hibernate HSQL dialect and float Java type is mapped to FLOAT type.
I also had a look on HSQL driver and I could see no problem neither.

Anyone encountered this problem ?
Anyone has an idea where it could come from (and a way to workaround it) ?
Is it a known problem with JDBC driver ? With Hibernate dialect ?

Thanks in advance,

Olivier


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/


_______________________________________________
Hsqldb-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/hsqldb-user

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Hsqldb-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/hsqldb-user
Reply | Threaded
Open this post in threaded view
|

Re: Problem with float property as query parameter in JPA

chawax
Thanks Fred. If I use DOUBLE, it works well with HSQLDB now. But I now have problems this time with MySQL ! It looks like MySQL uses float type internally, not double one, the opposite of HSQLDB. It's a nightmare ...

Anyway, I may use MySQL as production database while I will use HSQLDB for unit tests only, so I have to give prority to MySQL and I will keep my columns as float and will forgive unit tests with float values.

But is there a reason why you don't use float Java type for FLOAT columns and double Java type for DOUBLE columns ?

Olivier

2008/11/6 fredt <[hidden email]>
Java float is not used in HSQLDB. Only double is used internally. You should perhaps define your tables and other definitions using DOUBLE.
 
Fred
----- Original Message -----
Sent: 06 November 2008 13:17
Subject: [Hsqldb-user] Problem with float property as query parameter in JPA

Hi,

I use HSQLDB 1.8.0.10 with Hibernate 3.2.6.ga as JPA implementation.
But I encounter a strange problem : I have a query that has a where clause on a float property, I set the value for this property with a query parameter ... but it never returns any result, while it should !

My query is as following :

select v from ElementValue v where v.floatValue = :floatValue

floatValue field is defined as following in my EJB entity :

    @javax.persistence.Column(name = "FLOAT_VALUE_", insertable = true, updatable = true)
    public java.lang.Float getFloatValue()
    {
        return floatValue;
    }

When running unit tests, this query returns no result.
But when running the corresponding SQL query, it works well !
I tried different HQL queries in Hibernate console to understand what happens :
   
"select v from ElementValue v where v.floatValue = 3.14" => it works
"select v from ElementValue v where v.floatValue = :floatValue " floatValue query parameter has float Java type => no result
"select v from ElementValue v where v.floatValue = :floatValue " floatValue query parameter has double Java type => it works !

So it looks like there is a problem with type mapping for float query parameters.
I had a look on Hibernate HSQL dialect and float Java type is mapped to FLOAT type.
I also had a look on HSQL driver and I could see no problem neither.

Anyone encountered this problem ?
Anyone has an idea where it could come from (and a way to workaround it) ?
Is it a known problem with JDBC driver ? With Hibernate dialect ?

Thanks in advance,

Olivier


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/


_______________________________________________
Hsqldb-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/hsqldb-user

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Hsqldb-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/hsqldb-user



-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Hsqldb-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/hsqldb-user
Reply | Threaded
Open this post in threaded view
|

Re: Problem with float property as query parameter inJPA

Bayless Kirtley
That really sounds like a serious flaw if Mysql supports only float and not double. Are you sure it's not just some kind of a semantic problem?
 
Bayless
 
----- Original Message -----
Sent: Friday, November 07, 2008 4:29 AM
Subject: Re: [Hsqldb-user] Problem with float property as query parameter inJPA

Thanks Fred. If I use DOUBLE, it works well with HSQLDB now. But I now have problems this time with MySQL ! It looks like MySQL uses float type internally, not double one, the opposite of HSQLDB. It's a nightmare ...

Anyway, I may use MySQL as production database while I will use HSQLDB for unit tests only, so I have to give prority to MySQL and I will keep my columns as float and will forgive unit tests with float values.

But is there a reason why you don't use float Java type for FLOAT columns and double Java type for DOUBLE columns ?

Olivier

2008/11/6 fredt <[hidden email]>
Java float is not used in HSQLDB. Only double is used internally. You should perhaps define your tables and other definitions using DOUBLE.
 
Fred
----- Original Message -----
Sent: 06 November 2008 13:17
Subject: [Hsqldb-user] Problem with float property as query parameter in JPA

Hi,

I use HSQLDB 1.8.0.10 with Hibernate 3.2.6.ga as JPA implementation.
But I encounter a strange problem : I have a query that has a where clause on a float property, I set the value for this property with a query parameter ... but it never returns any result, while it should !

My query is as following :

select v from ElementValue v where v.floatValue = :floatValue

floatValue field is defined as following in my EJB entity :

    @javax.persistence.Column(name = "FLOAT_VALUE_", insertable = true, updatable = true)
    public java.lang.Float getFloatValue()
    {
        return floatValue;
    }

When running unit tests, this query returns no result.
But when running the corresponding SQL query, it works well !
I tried different HQL queries in Hibernate console to understand what happens :
   
"select v from ElementValue v where v.floatValue = 3.14" => it works
"select v from ElementValue v where v.floatValue = :floatValue " floatValue query parameter has float Java type => no result
"select v from ElementValue v where v.floatValue = :floatValue " floatValue query parameter has double Java type => it works !

So it looks like there is a problem with type mapping for float query parameters.
I had a look on Hibernate HSQL dialect and float Java type is mapped to FLOAT type.
I also had a look on HSQL driver and I could see no problem neither.

Anyone encountered this problem ?
Anyone has an idea where it could come from (and a way to workaround it) ?
Is it a known problem with JDBC driver ? With Hibernate dialect ?

Thanks in advance,

Olivier


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/


_______________________________________________
Hsqldb-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/hsqldb-user

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Hsqldb-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/hsqldb-user



-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/


_______________________________________________
Hsqldb-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/hsqldb-user

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Hsqldb-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/hsqldb-user
Reply | Threaded
Open this post in threaded view
|

Re: Problem with float property as query parameter inJPA

Graham Matthews
The SQL float type is in fact a double.

SQL real type is a float.

See 

http://java.sun.com/j2se/1.3/docs/guide/jdbc/getstart/mapping.html

graham

On Nov 7, 2008, at 6:19 AM, Bayless Kirtley wrote:

That really sounds like a serious flaw if Mysql supports only float and not double. Are you sure it's not just some kind of a semantic problem?
 
Bayless
 
----- Original Message -----
Sent: Friday, November 07, 2008 4:29 AM
Subject: Re: [Hsqldb-user] Problem with float property as query parameter inJPA

Thanks Fred. If I use DOUBLE, it works well with HSQLDB now. But I now have problems this time with MySQL ! It looks like MySQL uses float type internally, not double one, the opposite of HSQLDB. It's a nightmare ...

Anyway, I may use MySQL as production database while I will use HSQLDB for unit tests only, so I have to give prority to MySQL and I will keep my columns as float and will forgive unit tests with float values.

But is there a reason why you don't use float Java type for FLOAT columns and double Java type for DOUBLE columns ?

Olivier

2008/11/6 fredt <[hidden email]>
Java float is not used in HSQLDB. Only double is used internally. You should perhaps define your tables and other definitions using DOUBLE.
 
Fred
----- Original Message -----
Sent: 06 November 2008 13:17
Subject: [Hsqldb-user] Problem with float property as query parameter in JPA

Hi,

I use HSQLDB 1.8.0.10 with Hibernate 3.2.6.ga as JPA implementation.
But I encounter a strange problem : I have a query that has a where clause on a float property, I set the value for this property with a query parameter ... but it never returns any result, while it should !

My query is as following :

select v from ElementValue v where v.floatValue = :floatValue

floatValue field is defined as following in my EJB entity :

    @javax.persistence.Column(name = "FLOAT_VALUE_", insertable = true, updatable = true)
    public java.lang.Float getFloatValue()
    {
        return floatValue;
    }

When running unit tests, this query returns no result.
But when running the corresponding SQL query, it works well !
I tried different HQL queries in Hibernate console to understand what happens :
    
"select v from ElementValue v where v.floatValue = 3.14" => it works
"select v from ElementValue v where v.floatValue = :floatValue " floatValue query parameter has float Java type => no result
"select v from ElementValue v where v.floatValue = :floatValue " floatValue query parameter has double Java type => it works !

So it looks like there is a problem with type mapping for float query parameters.
I had a look on Hibernate HSQL dialect and float Java type is mapped to FLOAT type.
I also had a look on HSQL driver and I could see no problem neither.

Anyone encountered this problem ?
Anyone has an idea where it could come from (and a way to workaround it) ?
Is it a known problem with JDBC driver ? With Hibernate dialect ?

Thanks in advance,

Olivier



-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/



_______________________________________________
Hsqldb-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/hsqldb-user

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Hsqldb-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/hsqldb-user





-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/



_______________________________________________
Hsqldb-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/hsqldb-user
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/_______________________________________________
Hsqldb-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/hsqldb-user


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Hsqldb-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/hsqldb-user
Reply | Threaded
Open this post in threaded view
|

Re: Problem with float property as query parameter inJPA

Fred Toussi-2
In reply to this post by chawax
HSQLDB follows the SQL Standard which allows the implementation of FLOAT to have the same precision as DOUBLE. We implement both as Java Double in order to simplify the implementation.
 
Fred
----- Original Message -----
Sent: 07 November 2008 10:29
Subject: Re: [Hsqldb-user] Problem with float property as query parameter inJPA

Thanks Fred. If I use DOUBLE, it works well with HSQLDB now. But I now have problems this time with MySQL ! It looks like MySQL uses float type internally, not double one, the opposite of HSQLDB. It's a nightmare ...

Anyway, I may use MySQL as production database while I will use HSQLDB for unit tests only, so I have to give prority to MySQL and I will keep my columns as float and will forgive unit tests with float values.

But is there a reason why you don't use float Java type for FLOAT columns and double Java type for DOUBLE columns ?

Olivier

2008/11/6 fredt <[hidden email]>
Java float is not used in HSQLDB. Only double is used internally. You should perhaps define your tables and other definitions using DOUBLE.
 
Fred
----- Original Message -----
Sent: 06 November 2008 13:17
Subject: [Hsqldb-user] Problem with float property as query parameter in JPA

Hi,

I use HSQLDB 1.8.0.10 with Hibernate 3.2.6.ga as JPA implementation.
But I encounter a strange problem : I have a query that has a where clause on a float property, I set the value for this property with a query parameter ... but it never returns any result, while it should !

My query is as following :

select v from ElementValue v where v.floatValue = :floatValue

floatValue field is defined as following in my EJB entity :

    @javax.persistence.Column(name = "FLOAT_VALUE_", insertable = true, updatable = true)
    public java.lang.Float getFloatValue()
    {
        return floatValue;
    }

When running unit tests, this query returns no result.
But when running the corresponding SQL query, it works well !
I tried different HQL queries in Hibernate console to understand what happens :
   
"select v from ElementValue v where v.floatValue = 3.14" => it works
"select v from ElementValue v where v.floatValue = :floatValue " floatValue query parameter has float Java type => no result
"select v from ElementValue v where v.floatValue = :floatValue " floatValue query parameter has double Java type => it works !

So it looks like there is a problem with type mapping for float query parameters.
I had a look on Hibernate HSQL dialect and float Java type is mapped to FLOAT type.
I also had a look on HSQL driver and I could see no problem neither.

Anyone encountered this problem ?
Anyone has an idea where it could come from (and a way to workaround it) ?
Is it a known problem with JDBC driver ? With Hibernate dialect ?

Thanks in advance,

Olivier


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/


_______________________________________________
Hsqldb-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/hsqldb-user

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Hsqldb-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/hsqldb-user



-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/


_______________________________________________
Hsqldb-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/hsqldb-user

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Hsqldb-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/hsqldb-user