我正在使用JPA和Hibernate 3以及Spring 3.5。 我无法在hibernate之外的后端(通过直接查询)对数据库中所做的更改进行JPA / hibernate刷新。 我正在使用EHCache和二级缓存。以下是关键配置项:
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<!-- key properties pulled from prop file -->
<property name="driverClass" value="${dataSource.driverClassName}"/>
<property name="jdbcUrl" value="${dataSource.url}"/>
<property name="user" value="${dataSource.username}"/>
<property name="password" value="${dataSource.password}"/>
<property name="maxPoolSize" value="50"/>
<property name="maxIdleTime" value="14400"/>
<property name="checkoutTimeout" value="5000"/>
<property name="idleConnectionTestPeriod" value="60"/>
<property name="preferredTestQuery" value="select 1"/>
<property name="maxAdministrativeTaskTime" value="300"/>
<property name="numHelperThreads" value="10"/>
</bean>
<!-- We are Using JPA -->
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="persistenceXmlLocation" value="classpath:persistence.xml"/>
<property name="jpaProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
<prop key="hibernate.use_sql_comments">false</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.generate_statistics">true</prop>
<prop key="hibernate.cache.region.factory_class">net.sf.ehcache.hibernate.EhCacheRegionFactory</prop>
<prop key="hibernate.cache.use_query_cache">true</prop>
<prop key="hibernate.cache.use_second_level_cache">true</prop>
<prop key="hibernate.cache.use_structured_entries">true</prop>
<prop key="hibernate.cache.generate_statistics">true</prop>
</props>
</property>
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"/>
</property>
</bean>
对于与实体交互的所有方法,我也使用JpaTransactionManager和Propagation = REQUIRED。
请指教。
答案 0 :(得分:0)
通过“后门”更改数据库与使用orm特别是缓存相矛盾。
我会尽量避免这种情况(虽然我知道你需要它)。
使用后门冷的解决方案是: