我试图记录我从.xml文件调用的SQL查询。我面临的问题是,当我看到日志时,它的格式不正确。另外,我不知道为什么它会重复......
[main] INFO org.dozer.DozerBeanMapper - 初始化dozer bean映射器的新实例。 [main] INFO org.dozer.DozerBeanMapper - 初始化dozer bean映射器的新实例。 [main] INFO org.springframework.orm.hibernate5.HibernateTransactionManager - 使用Hibernate SessionFactory的DataSource [org.apache.commons.dbcp2.BasicDataSource@1f03fba0]进行HibernateTransactionManager [main] INFO org.springframework.aop.framework.CglibAopProxy - 无法代理方法[public final void com.servicios.test.TestRestauranteManager.findProveedoresByIdRestaurante()抛出com.servicios.util.exceptions.AlergenosException],因为它是final:All通过代理调用此方法将不会路由到目标实例。 [main] INFO org.springframework.test.context.transaction.TransactionContext - 开始测试上下文的事务(1)[DefaultTestContext @ 436bd4df testClass = TestRestauranteManager,testInstance = com.servicios.test.TestRestauranteManager@6848a051,testMethod = findProveedoresByIdRestaurante @ TestRestauranteManager, testException = [null],mergedContextConfiguration = [MergedContextConfiguration @ 149b0577 testClass = TestRestauranteManager,locations =' {classpath:test-applicationContext.xml}',classes =' {}',contextInitializerClasses =' []',activeProfiles =' {}',propertySourceLocations =' {}',propertySourceProperties =' {}' ,contextLoader =' org.springframework.test.context.support.DelegatingSmartContextLoader',parent = [null]]];事务管理器[org.springframework.orm.hibernate5.HibernateTransactionManager@5740ff5e];回滚[true] 选择restaurant0 _。" ID_RESTAURANTE"作为ID_RESTA1_4_0_,restaurant0 _。" DESCRIPCION" as DESCRIPC2_4_0_,restaurant0 _。" ID_CADENA_RESTAURANTE"作为ID_CADEN3_4_0_来自" RESTAURANTE" restaurant0_ where restaurant0 _。" ID_RESTAURANTE" =? Hibernate:选择restaurant0 _。" ID_RESTAURANTE"作为ID_RESTA1_4_0_,restaurant0 _。" DESCRIPCION" as DESCRIPC2_4_0_,restaurant0 _。" ID_CADENA_RESTAURANTE"作为ID_CADEN3_4_0_来自" RESTAURANTE" restaurant0_ where restaurant0 _。" ID_RESTAURANTE" =? 绑定参数[1]为[BIGINT] - [0]
我想要像
这样的东西[main] INFO org.dozer.DozerBeanMapper - 初始化dozer bean映射器的新实例。 [main] INFO org.dozer.DozerBeanMapper - 初始化dozer bean映射器的新实例。 [主要] INFO org.springframework.orm.hibernate5.HibernateTransactionManager - 使用 DataSource [org.apache.commons.dbcp2.BasicDataSource@1f03fba0] of Hibernate SessionFactory for HibernateTransactionManager [main] INFO org.springframework.aop.framework.CglibAopProxy - 无法代理 方法[公共最终无效 com.servicios.test.TestRestauranteManager.findProveedoresByIdRestaurante() 抛出com.servicios.util.exceptions.AlergenosException]因为它是 final:通过代理调用此方法的所有内容都不会被路由到 目标实例。 [主要] INFO org.springframework.test.context.transaction.TransactionContext - 开始执行事务(1)以获取测试上下文[DefaultTestContext @ 436bd4df testClass = TestRestauranteManager,testInstance = com.servicios.test.TestRestauranteManager@6848a051,testMethod = findProveedoresByIdRestaurante @ TestRestauranteManager,testException = [null],mergedContextConfiguration = [MergedContextConfiguration @ 149b0577 testClass = TestRestauranteManager,locations = ' {classpath:test-applicationContext.xml}',classes =' {}', contextInitializerClasses =' []',activeProfiles =' {}', propertySourceLocations =' {}',propertySourceProperties =' {}', contextLoader = ' org.springframework.test.context.support.DelegatingSmartContextLoader&#39 ;, parent = [null]]];交易经理 [org.springframework.orm.hibernate5.HibernateTransactionManager@5740ff5e]; 休眠:选择 P" DESCRIPCION" as" descripcion", P" ID_PROVEEDOR" as" idProveedor"
from "RESTAURANTE_PROVEEDOR" rp inner join "PROVEEDOR" p on rp."ID_PROVEEDOR" = p."ID_PROVEEDOR" where rp."ID_RESTAURANTE" = ? binding parameter [1] as [BIGINT] - [0]
我的log4j.properties如下:
log4j.rootLogger=INFO, stdout
log4j.logger.org.hibernate=INFO
log4j.logger.org.hibernate.SQL=TRACE
log4j.logger.org.hibernate.type=ALL
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.rootConsola.layout.ConversionPattern=(%d{dd/MM/yyyy-HH:mm:ss}) %-5p: %-40c{1} - %m%n
在我的ApplicationContext.xml中,我有这个
...
<bean id="sessionFactory"
class="org.springframework.orm.hibernate5.LocalSessionFactoryBean"
p:dataSource-ref="dataSource">
<property name="packagesToScan" value="com.servicios.vo"/>
<property name="mappingLocations">
<list>
<value>classpath*:hibernate/queries/**/*.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</prop>
<prop key="hibernate.ejb.naming_strategy">org.hibernate.cfg.ImprovedNamingStrategy</prop>
<prop key="hibernate.format_sql">true</prop>
</props>
</property>
</bean>
...
提前致谢!!
答案 0 :(得分:3)
当发生某些事情并抛出包含SQL片段的异常时,hibernate.format_sql
设置不适用于异常原因。
换句话说,hibernate.format_sql
仅在Hibernate将要执行的SQL写入日志时才适用,而不是作为某些例外原因的一部分而包含在内。