简体   繁体   中英

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 ie where the default mapping from sql columns to java is defined? I am aware this could be done using entity class.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM