我使用Spring-Data-JDBC(不是JPA)并希望设置获取大小.
我知道classic org.springframwork.jdbc.core.JdbcTemplate
有一个setFetchSize(int)
方法,但我有Spring数据JDBC存储库:
org.springframework.data.repository.Repository;
org.springframework.data.jdbc.repository.query.Query;
/** This is a Spring Data <b>JDBC</b> (JDBC not JPA!). */
public interface UserDao extends Repository<User, Long> {
@Query(value = UserRowMapper.SELECT_BY_NAME_STATEMENT
rowMapperClass = UserRowMapper.class)
Optional<User> findByName(String name);
}
这是配置的相关部分:
@Configuration
@EnableJdbcRepositories
public class AppConfigSpringDataJdbc extends AbstractJdbcConfiguration {
@Autowired
private DataSource dataSource;
@Bean
public NamedParameterJdbcTemplate namedParameterJdbcTemplate() {
return new NamedParameterJdbcTemplate(this.dataSource);
}
}
所以我的问题是:How/Where to set the sql query fetch-size when using Spring-Data-JDBC, either by query or in general?
(The common solutions for Spring-Data-JPA will not work, because there is no 100 or 101annotation because it is JDBC)