首页 > 解决方案 > 使用 Java Streams 时出现 Eclipselink 错误

问题描述

我正在尝试使用Java 8 StreamsJpaRepository从表中读取数据,但我遇到了一些问题。

知道我应该如何解决这个问题吗?

import org.eclipse.persistence.config.HintValues;
import org.eclipse.persistence.config.ResultSetConcurrency;
import org.eclipse.persistence.config.ResultSetType;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.jpa.repository.QueryHints;
import org.springframework.stereotype.Repository;
import javax.persistence.QueryHint;
import java.util.stream.Stream;
import static org.eclipse.persistence.config.QueryHints.*;

@Repository
public interface CancelledDetailedHeaderRepository extends JpaRepository<Entity, Long> {

    @QueryHints(value = {
            @QueryHint(name = RESULT_SET_TYPE, value = ResultSetType.ForwardOnly),
            @QueryHint(name = RESULT_SET_CONCURRENCY, value = ResultSetConcurrency.ReadOnly),
            @QueryHint(name = JDBC_FETCH_SIZE, value = "" + 100),
            @QueryHint(name = SCROLLABLE_CURSOR, value = HintValues.TRUE)
    })
    @Query("SELECT h" + " FROM #{#entityName} h " +
            "WHERE h.status = ?1")
    Stream<Entity> findAllByStatus(String status);

}

Eclipselink 属性:

  @Override
protected Map<String, Object> getVendorProperties() {
    HashMap<String, Object> map = new HashMap<String, Object>();
    map.put("eclipselink.weaving", "false");
    map.put("eclipselink.ddl-generation", "none");
    map.put("eclipselink.query-results-cache", "false");
    map.put("eclipselink.logging.logger", "JavaLogger");
    map.put("eclipselink.logging.level", "FINE");
    map.put("eclipselink.logging.level.sql", "FINE");
    map.put("eclipselink.logging.parameters", "true");
    map.put(PersistenceUnitProperties.BATCH_WRITING, BatchWriting.JDBC);
    return map;
}

异常说明:

方法 [getContainerClass()] 不是调用对象 [ScrollableCursorPolicy(page size = 10)] 的有效方法

.

标签: springjpaspring-data-jpaeclipselink

解决方案


推荐阅读