我想知道查询执行时间,所以我遵循这个answer
<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?
答案 0 :(得分:2)
您是否尝试过将该属性写入persistence.xml
? (这只是猜测)
<?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>
没有persistence.xml
:
<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>