Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
363 views
in Technique[技术] by (71.8m points)

spring boot - Why does hibernate execute sql in clauses on initialisation

I am running a sample app based on https://github.com/yahoo/elide-spring-boot-example

I removed all the elide references, added my own domains. Its now a basic spring boot app using hibernate. I updated the application.yaml with the following in order to

  1. Use my own SQL Server DB and dialect
  2. Ignore liquibase changelog
  3. Ignore ddl-auto
spring:
    application:
      name: Elide
    jpa:
      properties:
        hibernate:
          default_batch_fetch_size: 100
          query:
            plan_cache_max_size: 64
            plan_parameter_metadata_max_size: 32
            in_clause_parameter_padding: true
      hibernate:
        show_sql: true
        naming:
          physical-strategy: 'misc.CustomPhysicalNamingStrategy'
        dialect: 'org.hibernate.dialect.SQLServerDialect'
        ddl-auto: 'none'
        jdbc:
          use_scrollable_resultset: true       
    datasource:
      url: 'jdbc:sqlserver://localhost;databaseName=MYDATABASE'
      username: 'username'
      password: 'password'
      driver-class-name: 'com.microsoft.sqlserver.jdbc.SQLServerDriver'
      validation-query: "SELECT 1"    
    liquibase:
      change-log: 'classpath:db/changelog/changelog.xml'
      enabled: false

When running the app with debug output, I notice thousands of lines of select statements in the form

Static select for one-to-many ... select ... from AUDIT_DETAIL auditdetai0_ where auditdetai0_.AUDIT_ACTION_TYPE_ID in (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
Static select for one-to-many ... select ... from AUDIT_DETAIL auditdetai0_ where auditdetai0_.AUDIT_ACTION_TYPE_ID in (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
Static select for one-to-many ... select ... from AUDIT_DETAIL auditdetai0_ where auditdetai0_.AUDIT_ACTION_TYPE_ID in (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
Static select for one-to-many ... select ... from AUDIT_DETAIL auditdetai0_ where auditdetai0_.AUDIT_ACTION_TYPE_ID in (?, ?, ?, ?, ?, ?, ?, ?, ?)

I have no specific queries written. I thought it might be the query plan cache as per Spring + Hibernate: Query Plan Cache Memory usage but adding the plan_cache_max_size doesnt make any difference. Why are these queries generated, and what should I do to avoid prevent this?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Looks like you have some initialization logic that does some lazy loading.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...