LazyInitializationException出现在一个环境中,但不在另一个环境中

时间:2019-07-24 20:46:15

标签: java hibernate lazy-initialization

我在一个环境中遇到了这个例外,但在另一个环境中却没有。这种情况不断发生,错误仅出现在生产中,而不出现在暂存或开发中。

org.hibernate.LazyInitializationException: could not initialize proxy - no Session

起初我以为这可能是配置文件,但是它们是相同的,除了那些与休眠完全无关的小东西。

这些是我的应用程序属性

datasource:
    url: ...
    username: ...
    password: ...
    hikari:
        data-source-properties:
            cachePrepStmts: true
            prepStmtCacheSize: 250
            prepStmtCacheSqlLimit: 2048
            useServerPrepStmts: true
jpa:
    database-platform: org.hibernate.dialect.MySQLInnoDBDialect
    database: MYSQL
    show_sql: true
    properties:
        hibernate.cache.use_second_level_cache: false
        hibernate.cache.use_query_cache: false
        hibernate.generate_statistics: true

使用@Transactional批注可以轻松解决该问题,但是,在开发和登台环境中,没有它,一切都可以工作。我想防止这种情况在将来发生,但永远无法确定LazyInit如果不直接在生产环境中进行测试就不会出现。

0 个答案:

没有答案
相关问题