【问题标题】:Why does hibernate execute sql in clauses on initialisation为什么hibernate在初始化的子句中执行sql
【发布时间】:2021-04-11 13:15:03
【问题描述】:

我正在运行一个基于 https://github.com/yahoo/elide-spring-boot-example 的示例应用程序

我删除了所有省略号引用,添加了我自己的域。它现在是一个使用休眠的基本 Spring Boot 应用程序。 我使用以下内容更新了 application.yaml 以

  1. 使用我自己的 SQL Server 数据库和方言
  2. 忽略 liquibase 更改日志
  3. 忽略 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

当运行带有调试输出的应用程序时,我注意到表单中有数千行选择语句

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 (?, ?, ?, ?, ?, ?, ?, ?, ?)

我没有写具体的查询。我认为这可能是查询计划缓存 Spring + Hibernate: Query Plan Cache Memory usage 但添加 plan_cache_max_size 没有任何区别。为什么会生成这些查询,我应该怎么做才能避免这种情况发生?

【问题讨论】:

    标签: spring-boot hibernate


    【解决方案1】:

    我认为 hibernate 只是构建了一个可能针对不同实体运行的查询的元数据映射。查询并未实际执行。缓慢是由 swagger 文档构造中的错误引起的。此后,elide 社区已经解决了这个问题。

    【讨论】:

      【解决方案2】:

      看起来你有一些初始化逻辑来做一些延迟加载。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-08-16
        • 1970-01-01
        • 2020-10-01
        • 2021-12-10
        • 1970-01-01
        • 1970-01-01
        • 2012-03-16
        • 1970-01-01
        相关资源
        最近更新 更多