SQLQuery option for Statement.setFetchSize(int) #1419

ssaarela opened this Issue Jun 25, 2015 · 6 comments


None yet

4 participants


Currently setting fetchSize hint for Statement requires custom implementation using SQLDetailedListener. As Statement.setFetchSize(int) is part of standard JDBC API, it would make sense to implement this in core API.


I suggest that we support setting the following Statement properties on configuration and query level:

  • maxFieldSize
  • maxRows
  • queryTimeout
  • fetchSize

Maybe like

query.setStatementOption(StatementOption.MAX_FIELD_SIZE, maxFieldSize)

@ssaarela @Shredder121 @johnktims What do you think about the enum style, it would pollute the SQLQuery namespace less than Bean setters.


I think that should scale well.
Then we can give an enum constant a default value as field.


On the other hand setters would be more intuitive than enum style - distinct methods work well with auto-complete whereas finding that kind of enum setters would require googling/documentation.

I would leave defaults as unset, null or empty Optional, for all of these. At least fetchSize might slow down other queries and there are other ways of defining timeouts. Instead of setting maxRows, most developers would/should use SQL based limit, etc. If, however, someone wants to use Querydsl for setting these at global level, then using a listener is not that hard.

gmokki commented Jul 1, 2015

Enum vs setters:

  • the enum cannot have any type-safety (string vs int vs boolean) on the parameter method (of course runtime checks catch problems)
  • adding many setters pollute the main class

How about a StatementOptions immutable object. Default is created with default constructor, builder might be overkill. That way code can apply the same combination of options easily to many statements.

And I agree with ssaarela that defaults should be null or empty Optional. There are no values for the any of the settings that are good for all jdbc drivers.

timowest commented Jul 1, 2015

An immutable StatementOptions class sounds good, it provides typesafety and adds only a single method in the query signature.

This was referenced Jul 31, 2015
@timowest timowest added this to the 4.0.3 milestone Jul 31, 2015
@Shredder121 Shredder121 closed this in #1461 Aug 1, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment