You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by Olivier THIERRY <ol...@gmail.com> on 2008/11/04 16:52:51 UTC

How to set Java / JDBC / SQL type mapping with Open EJB ?

Hi,

I use Open EJB 3.0 as embedded server to run unit tests, with Hibernate
3.2.6.ga as JPA implementation and HSQLDB as embedded database (memory
mode). It works perfect, much better than others I tried to use until now
(JBoss embedded for example).

Anyway I encounter a problem I can't find how to solve. I created the
following named query in orm.xml file :

        <named-query name="Element.findByFloatData">
            <query><![CDATA[select ev.element from ElementValue ev where
ev.data = :data and ev.floatValue = :floatValue]]></query>
        </named-query>

I have the following method to run this named query:

    public Collection findByFloatData(final Data data, final Float
floatValue)
        throws ElementDaoException
    {
        try
        {
            Query queryObject =
emanager.createNamedQuery("Element.findByFloatData");
            queryObject.setParameter("data", data);
            queryObject.setParameter("floatValue", floatValue);
            List results = queryObject.getResultList();
            return results;
        }
        catch (Exception ex)
        {
            throw new ElementDaoException(ex);
        }
    }

But it nevers returns any result, while I have no problem running the
similar queries with string or int columns instead of float one ! So it's
just a problem with floats. Moreover using Hibernate console, I could make
it work but I had to set my parameter as a double. So it looks like I have a
type mapping problem with floats between Java, JDBC and HSQLDB. For what I
understood this type mapping is configured on the application server. In
JBoss AS (the one I use in production), there's a file for this, called
standardjbosscmp-jdbc.xml. It defines for each database product and each
Java type the JDBC and SQL corresponding types. Do we have the equivalent
with Open EJB ? Or is there something I misunderstood with JPA ? Please tell
me if it's not a problem with Open EJB because I am not sure at all about
this.

Thanks in advance ;)

Olivier

Re: How to set Java / JDBC / SQL type mapping with Open EJB ?

Posted by Olivier THIERRY <ol...@gmail.com>.
I had a response about this problem, and this due to HSQDLB itself, not
Hibernate neither OpenEJB.
Actually HSQLDB nevers use Java float internally, just doubles, so I should
define my properties as double instead of float.

Olivier

2008/11/6 Olivier THIERRY <ol...@gmail.com>

> Thanks for your response.
>
> I should have known this was a problem with JPA implementation since the
> problem is the same when using Hibernate console, and Open EJB is not
> involved in this case !
>
> Anyway I can't test with Open JPA because I use some specific Hibernate
> features. So I will ask my question on Hibernate forums and I will report
> here, I am sure it's something that could be useful for many people.
>
> Olivier
>
> 2008/11/5 David Blevins <da...@visi.com>
>
>
>> On Nov 4, 2008, at 7:52 AM, Olivier THIERRY wrote:
>>
>>  But it nevers returns any result, while I have no problem running the
>>> similar queries with string or int columns instead of float one ! So it's
>>> just a problem with floats. Moreover using Hibernate console, I could
>>> make
>>> it work but I had to set my parameter as a double. So it looks like I
>>> have a
>>> type mapping problem with floats between Java, JDBC and HSQLDB. For what
>>> I
>>> understood this type mapping is configured on the application server. In
>>> JBoss AS (the one I use in production), there's a file for this, called
>>> standardjbosscmp-jdbc.xml. It defines for each database product and each
>>> Java type the JDBC and SQL corresponding types. Do we have the equivalent
>>> with Open EJB ? Or is there something I misunderstood with JPA ? Please
>>> tell
>>> me if it's not a problem with Open EJB because I am not sure at all about
>>> this.
>>>
>>
>>
>> Type mapping is all handled by the JPA provider.  I'd double check with
>> Hibernate.
>>
>> I know OpenJPA and other JPA implementations have logic that adapts their
>> JDBC usage to match the dialect of the database and the capabilities of its
>> JDBC driver.  Pretty sure I've seen a similar property for Hibernate.
>>
>> One quick test might be to temporarily switch your JPA provider to say
>> OpenJPA, which is certified, and see how it handles the query.
>>
>> -David
>>
>>
>
>
> --
> Seules 2 choses sont infinies : l'univers et la bêtise humaine ; et encore
> pour l'univers, je ne suis pas sûr … (Einstein)
>

Re: How to set Java / JDBC / SQL type mapping with Open EJB ?

Posted by Olivier THIERRY <ol...@gmail.com>.
Thanks for your response.

I should have known this was a problem with JPA implementation since the
problem is the same when using Hibernate console, and Open EJB is not
involved in this case !

Anyway I can't test with Open JPA because I use some specific Hibernate
features. So I will ask my question on Hibernate forums and I will report
here, I am sure it's something that could be useful for many people.

Olivier

2008/11/5 David Blevins <da...@visi.com>

>
> On Nov 4, 2008, at 7:52 AM, Olivier THIERRY wrote:
>
>  But it nevers returns any result, while I have no problem running the
>> similar queries with string or int columns instead of float one ! So it's
>> just a problem with floats. Moreover using Hibernate console, I could make
>> it work but I had to set my parameter as a double. So it looks like I have
>> a
>> type mapping problem with floats between Java, JDBC and HSQLDB. For what I
>> understood this type mapping is configured on the application server. In
>> JBoss AS (the one I use in production), there's a file for this, called
>> standardjbosscmp-jdbc.xml. It defines for each database product and each
>> Java type the JDBC and SQL corresponding types. Do we have the equivalent
>> with Open EJB ? Or is there something I misunderstood with JPA ? Please
>> tell
>> me if it's not a problem with Open EJB because I am not sure at all about
>> this.
>>
>
>
> Type mapping is all handled by the JPA provider.  I'd double check with
> Hibernate.
>
> I know OpenJPA and other JPA implementations have logic that adapts their
> JDBC usage to match the dialect of the database and the capabilities of its
> JDBC driver.  Pretty sure I've seen a similar property for Hibernate.
>
> One quick test might be to temporarily switch your JPA provider to say
> OpenJPA, which is certified, and see how it handles the query.
>
> -David
>
>


-- 
Seules 2 choses sont infinies : l'univers et la bêtise humaine ; et encore
pour l'univers, je ne suis pas sûr … (Einstein)

Re: How to set Java / JDBC / SQL type mapping with Open EJB ?

Posted by David Blevins <da...@visi.com>.
On Nov 4, 2008, at 7:52 AM, Olivier THIERRY wrote:

> But it nevers returns any result, while I have no problem running the
> similar queries with string or int columns instead of float one ! So  
> it's
> just a problem with floats. Moreover using Hibernate console, I  
> could make
> it work but I had to set my parameter as a double. So it looks like  
> I have a
> type mapping problem with floats between Java, JDBC and HSQLDB. For  
> what I
> understood this type mapping is configured on the application  
> server. In
> JBoss AS (the one I use in production), there's a file for this,  
> called
> standardjbosscmp-jdbc.xml. It defines for each database product and  
> each
> Java type the JDBC and SQL corresponding types. Do we have the  
> equivalent
> with Open EJB ? Or is there something I misunderstood with JPA ?  
> Please tell
> me if it's not a problem with Open EJB because I am not sure at all  
> about
> this.


Type mapping is all handled by the JPA provider.  I'd double check  
with Hibernate.

I know OpenJPA and other JPA implementations have logic that adapts  
their JDBC usage to match the dialect of the database and the  
capabilities of its JDBC driver.  Pretty sure I've seen a similar  
property for Hibernate.

One quick test might be to temporarily switch your JPA provider to say  
OpenJPA, which is certified, and see how it handles the query.

-David