我在应用程序 Spring + JPA + Hibernate 中有以下配置,使用 packagesToScan 来避免文件 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>
我的问题是:
- 是否有必要在两个地方都定义像 show_sql 或方言这样的属性?
- 哪个优先于另一个?
- 什么地方更适合定义呢?
提前致谢