I have the following configuration in an application Spring + JPA + Hibernate, using packagesToScan to avoid having file persistence.xml.
<!-- Configure JPA Implementation -->
<bean id="jpaVendorAdapter" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="database" value="${jpa.database}" />
<property name="showSql" value="${jpa.showSql}" />
<property name="databasePlatform" value="${jpa.dialect}" />
<property name="generateDdl" value="${jpa.generateDdl}" />
</bean>
<!-- Create the JPA EntityManagerFactory -->
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="jpaVendorAdapter" ref="jpaVendorAdapter"/>
<property name="packagesToScan">
<list>
<value>com.proyectofinal.model</value>
</list>
</property>
<property name="jpaProperty">
<props>
<entry key="hibernate.cache.use_second_level_cache" value="true"/>
<entry key="hibernate.cache.use_query_cache" value="true"/>
<entry key="hibernate.cache.provider_class" value="net.sf.ehcache.hibernate.SingletonEhCacheProvider"/>
<entry key="hibernate.show_sql" value="true" />
<entry key="hibernate.use_sql_comments" value="false" />
<entry key="hibernate.format_sql" value="true" />
<entry key="hibernate.dialect" value="org.hibernate.dialect.MYSQLDialect" />
<entry key="hibernate.temp.use_jdbc_metadata_defaults" value="false"/>
</props>
</property>
</bean>
My question is:
Thanks in advance
Properties specified in the JpaVendorAdapter don't have to be duplicated in the list of additional properties. If that would be the case the JpaVendorAdapter would be pretty useless.
Also in your configuration use either database or databasePlatform don't use both.
Properties which can be configured by using a JpaVendorAdapter I would configure right there, it would save you a couple of lines and you don't have to remember the cryptic hibernate (or which ever provider you use) property name.
The properties you need are the following.
<props>
<entry key="hibernate.cache.use_second_level_cache" value="true"/>
<entry key="hibernate.cache.use_query_cache" value="true"/>
<entry key="hibernate.cache.provider_class" value="net.sf.ehcache.hibernate.SingletonEhCacheProvider"/>
<entry key="hibernate.use_sql_comments" value="false" />
<entry key="hibernate.format_sql" value="true" />
<entry key="hibernate.temp.use_jdbc_metadata_defaults" value="false"/>
</props>
If you define them in both places the one from the JpaVendorAdapter are ignored.
In addition to @M. Deinum's answer, if you decide to use the jpaProperties over jpaVendorAdapter, you'll need to set the persistenceProvider property since it would normally be derived from jpaVendorAdapter
for example
<property name="persistenceProvider">
<bean class="org.hibernate.ejb.HibernatePersistence"/>
</property>
Also, jpaProperty should be jpaProperties
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With