成功设置刷新缓存的方法是,如下
EntityManager em = Entity.entityManager();
q1 = em.createNativeQuery("sql", XXX.class).
setHint(QueryHints.REFRESH, HintValues.TRUE);
主要是设置 ( QueryHints.REFRESH, HintValues.TRUE)
另外据说在jpa的配置文件 persistence.xml中加上一段
<property name="eclipselink.query-results-cache" value="false"/>
不过,我这个项目还不起作用。
persistence.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="persistenceUnit" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<validation-mode>NONE</validation-mode>
<properties>
<property name="eclipselink.target-database" value="com.sap.persistence.platform.database.HDBPlatform"/>
<!-- value="drop-and-create-tables" to build a new database on each run; value="create-tables" creates new tables if needed; value="none" makes no changes to the database -->
<property name="eclipselink.ddl-generation" value="none"/>
<property name="eclipselink.ddl-generation.output-mode" value="database"/>
<property name="eclipselink.weaving" value="static"/>
<property name="eclipselink.query-results-cache" value="false"/>
</properties>
</persistence-unit>
</persistence>