Search code examples
javajpa-1.0

What is JPA 1.0 named native query default mapping to scalar values


In JPA 1.0 (TopLink Essentials) I have a native named query:

@NamedNativeQuery(name = "findC1andC2",
query="select c1, c2 from t1 where c3=? order by c4 desc")

where c1 in Oracle DB is number(5, 0), and c2 is number(6, 0). When

Object object = em.createNamedQuery("findC1andC2").setParameter(1, "x").setMaxResults(1).getSingleResult();

following:
Object which getClass() returns java.util.Vector

and, when:
java.util.Vector vector = (java.util.Vector)object;

following:
vector.get(0).getClass() returns java.math.BigDecimal
vector.get(1).getClass() returns java.math.BigDecimal

Is is possible Long to be returned for these 2 fields i.e. where the default mapping from sql columns to java is defined? I am aware this could be done using entity class.


Solution

  • JPA implentations uses JDBC internally. According to Oracle data mapping tables. NUMERIC types is mapped to java.math.BigDecimal.

    According to this SO answer, it's not yet possible to do pure native scalar mapping with JPA Query but you can create a Facade to be returned by the query.

    I hope this helps.