Spring 如何在日志中获取查询执行时间
我想知道查询执行时间,所以我遵循以下步骤Spring 如何在日志中获取查询执行时间,spring,hibernate,jpa,spring-data,Spring,Hibernate,Jpa,Spring Data,我想知道查询执行时间,所以我遵循以下步骤 您是否尝试将属性写入persistence.xml?(这只是猜测) 我不使用persistence.xml,我必须?我直接使用persistence.xml只是设置泛型属性的一种方法,但我会给它一个try@Youssef:我添加了一个示例,说明如何在不使用persistence.xml的情况下设置属性。这取决于您-一个单独的文件将传播有关不同位置/文件的信息,但是如果有很多属性,那么最好将它们放在不同的文件中,而不是放在一个文件中。 <bea
您是否尝试将属性写入
persistence.xml
?(这只是猜测)
我不使用
persistence.xml
,我必须?我直接使用
persistence.xml只是设置泛型属性的一种方法,但我会给它一个try@Youssef:我添加了一个示例,说明如何在不使用persistence.xml的情况下设置属性。这取决于您-一个单独的文件将传播有关不同位置/文件的信息,但是如果有很多属性,那么最好将它们放在不同的文件中,而不是放在一个文件中。
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceUnitName" value="persistenceYous" />
<property name="dataSource" ref="dataSource" />
<property name="packagesToScan" value="persistence" />
<property name="jpaVendorAdapter" ref="jpaVendorAdapter" />
</bean>
<bean id="jpaVendorAdapter" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="showSql" value="true" />
<property name="generate_statistics" value="true" />
</bean>
Caused by: org.springframework.beans.NotWritablePropertyException:
Invalid property 'generate_statistics' of bean class [org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter]:
Bean property 'generate_statistics' is not writable or has an invalid setter method.
Does the parameter type of the setter match the return type of the getter?
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit ...>
...
<properties>
...
<property name="hibernate.generate_statistics" value="true" />
</properties>
...
</persistence-unit>
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
...
<property name="jpaVendorAdapter" .../>
<property name="jpaPropertyMap">
<map>
<entry key="hibernate.generate_statistics" value="true"/>
</map>
</property>
</bean>