icyerasor
icyerasor

Reputation: 5242

Spring boot won't use hibernates default_batch_fetch_size

Tried to configure hibernates default_batch_fetch_size through the spring application.yml. AFAIK the setting has the same effect as putting @BatchSize(size = xxx) annotations on all your entity-relationships.

I enabled spring.jpa.properties.hibernate.generate_statistics: true and logging accordingly and tried setting

spring:
  jpa:
    properties:
      hibernate:
        jdbc:
          batch_size: 100
          default_batch_fetch_size: 30

I also tried

spring:
  jpa:
    hibernate:
      ddl-auto: none
      default_batch_fetch_size: 30

but that configuration property doesn't seem to exist at all.

Resulting Logs show that hibernate won't fetch collections batched, but N+1 (FetchMode is not specified - thus the default @Fetch(FetchMode.SELECT) is used - and I don't want to change that).

Upvotes: 2

Views: 1465

Answers (1)

icyerasor
icyerasor

Reputation: 5242

Turns out I mixed up where to put the property-config. The right path is something like this:

spring:
  jpa:
    properties:
      hibernate:
        default_batch_fetch_size: 30
        jdbc:
          batch_size: 100

Upvotes: 2

Related Questions