I'm working on a project that uses JPA (Hibernate), so almost all the queries are written in JPQL. But for a query I need to get down to the specific database type, so I've written a native query.
The project actually is tested with both MySQL and Oracle DBMS. My native query is a "SELECT 1 FROM [...]"
; I then need to know if the result exists (easy) and if it's 1 (you could argue that's reduntant, I guess :-)).
In both cases I'm creating a javax.persistence.Query
with createNativeQuery(String)
and I run the query like this: Object r = q.getSingleResult();
(exceptions are taken care of already).
What I'm finding is that on MySQL r is a BigInteger
, while in Oracle is of class BigDecimal
.
I'm a nood at JDBC, is there any way (changing the query, the objects or the method calls I'm using) that I can be sure that my query will return the same datatype no matter what the database system is run against? Is this something that can be configured, that depends on jdbc, or is a driver-specific problem?