使用Hibernate作为JPA提供程序插入/更新数据库后,不会更新EhCache
首先, 我有一个使用JPA/Hibernate设计的持久化应用程序,一个JMS队列和一个与第三方系统的SOAP Web服务接口。该应用程序在集群JBoss EAP 6.0服务器中运行 共有两个数据库,第一个是Oracle 10g数据库,我从中获取所有要处理的数据,第二个是PostgreSQL数据库,我将处理结果持久化到其中。PostgreSQL数据库用作持久缓存,因为处理Oracle 10g数据库中的数据需要花费太多时间。整个过程如下:使用Hibernate作为JPA提供程序插入/更新数据库后,不会更新EhCache,hibernate,java-ee-6,ehcache,Hibernate,Java Ee 6,Ehcache,首先, 我有一个使用JPA/Hibernate设计的持久化应用程序,一个JMS队列和一个与第三方系统的SOAP Web服务接口。该应用程序在集群JBoss EAP 6.0服务器中运行 共有两个数据库,第一个是Oracle 10g数据库,我从中获取所有要处理的数据,第二个是PostgreSQL数据库,我将处理结果持久化到其中。PostgreSQL数据库用作持久缓存,因为处理Oracle 10g数据库中的数据需要花费太多时间。整个过程如下: 从Oracle 10g数据库获取数据 处理数据并生成结果
- 从Oracle 10g数据库获取数据
- 处理数据并生成结果
- 将结果异步发送到持久JMS队列,并将结果作为WebService XML返回
- MDB使用队列中的结果,并使用JPA将其保存在数据库中
<persistence-unit name="sDs" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:jboss/datasources/sDs</jta-data-source>
<shared-cache-mode>DISABLE_SELECTIVE</shared-cache-mode>
<mapping-file>META-INF/jpql/NamedQueries.xml</mapping-file>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<class>x.AusenciaX</class>
<properties>
<property name="hibernate.cache.provider_class" value="net.sf.ehcache.hibernate.EhCacheProvider" />
<property name="hibernate.cache.region.factory_class" value="org.hibernate.cache.ehcache.EhCacheRegionFactory" />
<property name="hibernate.cache.default_cache_concurrency_strategy" value="read-write" />
<property name="hibernate.cache.use_second_level_cache" value="false"/>
<property name="hibernate.cache.use_query_cache" value="false"/>
<property name="hibernate.default_schema" value="sisfpj" />
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" />
<property name="hibernate.generate_statistics" value="true" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.format_sql" value="true" />
</properties>
</persistence-unit>
org.hibernate.ejb.HibernatePersistence
java:jboss/datasources/sDs
禁用_选择性
META-INF/jpql/namedquerys.xml
真的
x、 奥森西克斯
ehcache.xml:
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="ehcache.xsd"
updateCheck="false" monitoring="autodetect"
dynamicConfig="true">
<defaultCache
maxElementsInMemory="1000"
eternal="false"
timeToIdleSeconds="86400"
timeToLiveSeconds="86400"
overflowToDisk="true"
/>
</ehcache>
提前感谢。回答您的第一部分,缓存只有在我查询两次后才能工作。第一次它将查询数据库并将其加载到缓存中,因此第二次查询时它将从缓存而不是数据库中加载。可能是因为在persistence.xml文件中的行
hibernate.cache。使用第二级缓存必须设置为true
否则您的缓存将不会被使用。但即使我强制它以编程方式进行第二次查询,它也不会填充缓存。为什么会发生这种情况?