简体   繁体   English

Spring数据JPA将数据作为Object列表流获取

[英]Spring data JPA fetch data as stream of list of Object

I've a Spring web application which uses Spring Data JPA to interact with DB. 我有一个Spring Web应用程序,它使用Spring Data JPA与DB进行交互。 I've a table consisting millions of records and I want to export a CSV consisting huge amount of data, for this I considered using Stream. 我有一个包含数百万条记录的表,我想导出一个包含大量数据的CSV,为此我考虑使用Stream。

@Query(value = "SELECT * FROM table WHERE id=:id", nativeQuery = true)
public Stream<Object[]> getData(@Param("id") long id);

Executing query works fine and I get the data as stream but the problem occurs when I try to process the stream and I get ClassCastException ie BigInteger cannot be cast to Object . 执行查询工作正常,我将数据作为流获取,但当我尝试处理流时出现问题,我得到ClassCastExceptionBigInteger不能转换为Object Can someone please suggest where I'm mistaking. 有人可以建议我在哪里误会。

You got ClassCastException because it fetches only first field in select query which may be a numeric type. 您有ClassCastException,因为它只获取select查询中的第一个字段,该字段可能是数字类型。 I have the same problem and updating spring-boot-starter-parent to version 1.4.1.RELEASE make it works. 我有同样的问题,并将spring-boot-starter-parent更新为版本1.4.1.RELEASE使其工作。 (spring-data-jpa: 1.10.3.RELEASE hibernate-core: 5.0.11.Final) (spring-data-jpa:1.10.3.RELEASE hibernate-core:5.0.11.Final)

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

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