使用弹簧数据进行休眠日志记录

时间:2021-06-30 08:01:50

标签: hibernate logging spring-data-jpa

我尝试在本文中做类似的事情:

Enable hibernate logging with spring data?

但没有记录任何内容。 当我离开 application.properties 中的条目时,会记录 sql 查询。 看起来 jpaproperties 中设置 show_sql=true 和
之间存在冲突 application.properties 中的 spring.jpa.show-sql=true 。我尝试将 show_sql 设置为 true、false 并将其完全省略,但未记录查询。

相关内容如下:

application.properties

spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true

注解配置:

@Bean(name = "entityManagerFactory")
public LocalContainerEntityManagerFactoryBean entityManagerFactoryBean() 
{
    final LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();
    entityManagerFactoryBean.setJpaVendorAdapter(vendorAdaptor());
    entityManagerFactoryBean.setDataSource(dataSource());
    entityManagerFactoryBean.setPersistenceProviderClass(HibernatePersistenceProvider.class);
    entityManagerFactoryBean.setPackagesToScan(this.env.getProperty("packagestoscan"));
    entityManagerFactoryBean.setJpaProperties(jpaHibernateProperties());
    return entityManagerFactoryBean;
}

protected Properties jpaHibernateProperties()
{

    final Properties properties = new Properties();

    properties.put("hibernate.dialect",org.hibernate.dialect.Oracle10gDialect);
    properties.put("hibernate.show_sql", true);
    properties.put("hibernate.format_sql", true);

    return properties;
}


@Bean
public HibernateJpaVendorAdapter vendorAdaptor()
{
    final HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
    return vendorAdapter;
}

使用

logging.level.org.hibernate.SQL=DEBUG
logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE

也没有记录查询。

我在这里遗漏了什么吗?谢谢!

0 个答案:

没有答案