Second Level Cache - JPA and EclipseLink

2

I would like to completely disable the JPA / EclipseLink cache, but I can not.

I can disable the first level cache using:

query.setHint("javax.persistence.cache.storeMode", CacheStoreMode.REFRESH)

But the second level cache is not disabled.

What should I do to get the subtables (@ManyToOne) fetched directly from the BD without caching?

Persistence.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
  <persistence-unit name="br.com.empresa_Sistema_war_1.0-SNAPSHOTPU" transaction-type="JTA">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <jta-data-source>jdbc/sistema</jta-data-source>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <shared-cache-mode>NONE</shared-cache-mode>
    <properties>
      <property name="eclipselink.cache.shared.default" value="false"/>
      <property name="eclipselink.query-results-cache" value="false"/>
      <property name="eclipselink.refresh" value="true"/>
      <property name="eclipselink.logging.level" value="FINE"/>
    </properties>
  </persistence-unit>
</persistence>
    
asked by anonymous 11.09.2015 / 22:07

1 answer

1

The problem was in the statement of EntityManager used to retrieve query items:

private static final EntityManager em = Persistence.createEntityManagerFactory("br.com.empresa_Sistema_war_1.0-SNAPSHOTPU").createEntityManager();  

I started using EntityManager of Facade of the entity and the cache was no longer used, with the Persistence.xml settings listed above prevailing.

Facade

@PersistenceContext(unitName = "br.com.empresa_Sistema_war_1.0-SNAPSHOTPU")
protected abstract EntityManager getEntityManager();

public EntityManager getEM() {
    return getEntityManager();
}

I did not even need to use setHint() to set CacheStoreMode , which in EM earlier only worked to disable the main entity cache, not working for second level entities.

    
12.09.2015 / 07:36