Java – priority between hibernate jpavendoradapter and attributes in JPA property

I have the following configuration in an application spring JPA hibernate. I use packagestoscan to avoid using the 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:

>Is it necessary to define show in two places_ Attributes such as SQL or dialect? > Which takes precedence over the other? > Which place is better to define it?

Thank you in advance

Solution

The attributes specified in the jpavendoradapter do not have to be repeated in other attribute lists If so, the JPA vendor adapter will be useless

Also, use database or database platform in your configuration. Do not use them at the same time

Properties that can be configured using the JPA vendoradapter. I'll configure them there. It can save you a few lines, and you don't have to remember the mysterious hibernate (or provider) property name

The attributes you need are as follows

<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 they are defined in two locations, one of the JPA vendor adapters is ignored

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>