I am using JPA with Hibernate 3 and Spring 3.5.
I am unable to make JPA/hibernate refresh to changes made in database in the backend outside of hibernate (via direct queries).
I am using EHCache , and second level caching. Following are the key configuration items:
<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>
I am also using JpaTransactionManager with Propagation=REQUIRED for all methods interacting with entities.
Please advice.
Changing the database through the “back door” is in contradiction to using a orm especially with a cache.
I would try to avoid this situation completely (although I know that you have needs for it).
A solution using the back door cold be: