简体   繁体   English

单列的JPA本机查询

[英]JPA native query with single column

I need some help how to return just one column which is date as sample below. 我需要一些帮助,如何返回仅一列,即以下示例的日期。 cuurently getting exception. 不断得到例外。 is there to return java Date directly? 是否可以直接返回java Date?

    Query currentAsOf = em.createNativeQuery("SELECT CURRENT_AS_OF FROM VW_OP_MKT_OFFERS",java.util.Date.class);

Will appreciate any help? 会感谢您的帮助吗?

You only use the createNativeQuery with a class to pass in an entity class that is to be built from the results. 您只能将createNativeQuery与一个类一起使用,以传入要从结果中构建的实体类。 If all you want is raw data, just pass in the SQL string to createNativeQuery and it will return the data as a list of Object[]: 如果您只需要原始数据,只需将SQL字符串传递给createNativeQuery,它将以Object []的列表形式返回数据:

Query currentAsOf = em.createNativeQuery("SELECT CURRENT_AS_OF FROM VW_OP_MKT_OFFERS");
List<Object[]> results = currentAsOf.getResultList();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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