Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

734
Views
How to set fetch-size in Spring-Data-JDBC

I use Spring-Data-JDBC (not JPA) and want to set the fetch-size.

I know that the the classic org.springframwork.jdbc.core.JdbcTemplate has a setFetchSize(int) method, but I have Spring-Data-JDBC repository:

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);
}

and this is the relevant part of the configuration:

@Configuration
@EnableJdbcRepositories 
public class AppConfigSpringDataJdbc extends AbstractJdbcConfiguration {
   @Autowired
   private DataSource dataSource;

   @Bean
   public NamedParameterJdbcTemplate namedParameterJdbcTemplate() {
       return new NamedParameterJdbcTemplate(this.dataSource);
   }
}

So my question is: 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 persistence.xml or javax.persistence.QueryHintannotation because it is JDBC)

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You can create NamedParameterJdbcTemplate using custom JdbcTemplate.

@Bean
JdbcOperations jdbcOperations(DataSource dataSource) {
    final var jdbcTemplate = new JdbcTemplate(dataSource);
    jdbcTemplate.setFetchSize(100);
    return jdbcTemplate;
}

@Bean
NamedParameterJdbcOperations namedParameterJdbcOperations(JdbcOperations operations) {
    return new NamedParameterJdbcTemplate(operations);
}
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!