gpt4 book ai didi

java - 即使启用所有属性后,Hibernate 也不记录触发的 SQL 查询

转载 作者:行者123 更新时间:2023-11-30 06:32:05 27 4
gpt4 key购买 nike

我使用 hibernate 属性启用了日志记录,但仍然看不到正在触发的 SQL 查询

这是我的 Spring 配置代码:

        @Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
em.setDataSource(dataSource());
em.setPackagesToScan("models");

final HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
em.setJpaVendorAdapter(vendorAdapter);
em.setJpaProperties(hibernateProperties());
return em;
}
private Properties hibernateProperties() {
return new Properties() {
{
setProperty("hibernate.hbm2ddl.auto", hbm2ddlScheme);
setProperty("hibernate.dialect", dbDialect);
setProperty("hibernate.globally_quoted_identifiers", "true");
setProperty("hibernate.use_sql_comments", "true");
setProperty("hibernate.generate_statistics", "true");
setProperty("format_sql", formatSQL);
setProperty("show_sql", showSQL);
setProperty("hibernate.cache.region.factory_class", "org.hibernate.cache.ehcache.EhCacheRegionFactory");
setProperty("hibernate.cache.use_second_level_cache", "true");
setProperty("hibernate.cache.use_query_cache", "true");
setProperty("hibernate.cache.use_structured_entries", "true");
setProperty("net.sf.ehcache.configurationResourceName", "myehcache.xml");
}
};
}

不过我确实看到了 session 统计数据。我还想查看正在触发的查询。

最佳答案

尝试使用 hibernate.show_sqlhibernate.format_sql 而不是 show_sqlformat_sql

关于java - 即使启用所有属性后,Hibernate 也不记录触发的 SQL 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45899170/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com