Dieser Inhalt ist in der von Ihnen ausgewählten Sprache nicht verfügbar.

19.8. JPA Cache Store


The JPA (Java Persistence API) Cache Store stores cache entries in the database using a formal schema, which allows other applications to read the persisted data and load data provided by other applications into Red Hat JBoss Data Grid. The database should not be used by the other applications concurrently with JBoss Data Grid.

Important

In Red Hat JBoss Data Grid, JPA cache stores are only supported in Library mode.

19.8.1. JPA Cache Store Sample XML Configuration (Library Mode)

To configure JPA Cache Stores using XML in Red Hat JBoss Data Grid, add the following configuration to the infinispan.xml file:
<local-cache name="users">
  <!-- Insert additional configuration elements here -->
	<persistence passivation="false">
            <jpa-store xmlns="urn:infinispan:config:store:jpa:8.0"
                      shared="true"
                      preload="true"
                      persistence-unit="MyPersistenceUnit"
                      entity-class="org.infinispan.loaders.jpa.entity.User" />
	</persistence>
</local-cache>
Copy to Clipboard Toggle word wrap
For details about the elements and parameters used in this sample configuration, see Section 19.2, “Cache Store Configuration Details (Library Mode)”.

19.8.2. Storing Metadata in the Database

When storeMetadata is set to true (default value), meta information about the entries such as expiration, creation and modification timestamps, and versioning is stored in the database. JBoss Data Grid stores the metadata in an additional table named __ispn_metadata__ because the entity table has a fixed layout that cannot accommodate the metadata.
The structure of this table depends on the database in use. Enable the automatic creation of this table using the same database as the test environment and then transfer the structure to the production database.

Procedure 19.3. Configure persistence.xml for Metadata Entities

  1. Using Hibernate as the JPA implementation allows automatic creation of these tables using the property hibernate.hbm2ddl.auto in persistence.xml as follows:
    <property name="hibernate.hbm2ddl.auto" value="update"/>
    Copy to Clipboard Toggle word wrap
  2. Declare the metadata entity class to the JPA provider by adding the following to persistence.xml:
    <class>org.infinispan.persistence.jpa.impl.MetadataEntity</class>
    Copy to Clipboard Toggle word wrap
As outlined, metadata is always stored in a new table. If metadata information collection and storage is not required, set the storeMetadata attribute to false in the JPA Store configuration.

19.8.3. Deploying JPA Cache Stores in Various Containers

Red Hat JBoss Data Grid's JPA Cache Store implementations are deployed normally for all supported containers, except Red Hat JBoss Enterprise Application Platform. JBoss Data Grid's JBoss EAP modules contain the JPA cache store and related libraries (such as Hibernate). As a result, the relevant libraries are not packaged inside the application, but instead the application refers to the libraries in the JBoss EAP modules that have them installed.
These modules are not required for containers other than JBoss EAP. As a result, all the relevant libraries are packaged in the application's WAR/EAR file, such as with the following Maven dependency:
<dependency>
    <groupId>org.infinispan</groupId>
    <artifactId>infinispan-cachestore-jpa</artifactId>
    <version>8.3.0.Final-redhat-1</version>
</dependency>
Copy to Clipboard Toggle word wrap

Procedure 19.4. Deploy JPA Cache Stores in JBoss EAP 6.3.x and earlier

  • To add dependencies from the JBoss Data Grid modules to the application's classpath, provide the JBoss EAP deployer a list of dependencies in one of the following ways:
    1. Add a dependency configuration to the MANIFEST.MF file:
      Manifest-Version: 1.0
      Dependencies: org.infinispan:jdg-7.0 services, org.infinispan.persistence.jpa:jdg-7.0 services
      Copy to Clipboard Toggle word wrap
    2. Add a dependency configuration to the jboss-deployment-structure.xml file:
      <jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2">
          <deployment>
              <dependencies>
                  <module name="org.infinispan.persistence.jpa" slot="jdg-7.0" services="export"/>
                  <module name="org.infinispan" slot="jdg-7.0" services="export"/>
              </dependencies>
          </deployment>
      </jboss-deployment-structure>
      Copy to Clipboard Toggle word wrap

Procedure 19.5. Deploy JPA Cache Stores in JBoss EAP 6.4 and later

  1. Add the following property in persistence.xml:
    <persistence-unit>
      [...]
      <properties>
        <property name="jboss.as.jpa.providerModule" value="application" />
      </properties>
    </persistence-unit>
    Copy to Clipboard Toggle word wrap
  2. Add the following dependencies to the jboss-deployment-structure.xml:
    <jboss-deployment-structure>
        <deployment>
            <dependencies>
                <module name="org.infinispan" slot="jdg-7.0"/>
                <module name="org.jgroups" slot="jdg-7.0"/>
                <module name="org.infinispan.persistence.jpa" slot="jdg-7.0" services="export"/>
                <module name="org.hibernate"/>
            </dependencies>
        </deployment>
    </jboss-deployment-structure>
    Copy to Clipboard Toggle word wrap
  3. Add any additional dependencies, such as additional JDG modules, are in use add these to the dependencies section in jboss-deployment-structure.xml.

Important

JPA Cache Store is not supported in Apache Karaf in JBoss Data Grid 7.0.
Nach oben
Red Hat logoGithubredditYoutubeTwitter

Lernen

Testen, kaufen und verkaufen

Communitys

Über Red Hat Dokumentation

Wir helfen Red Hat Benutzern, mit unseren Produkten und Diensten innovativ zu sein und ihre Ziele zu erreichen – mit Inhalten, denen sie vertrauen können. Entdecken Sie unsere neuesten Updates.

Mehr Inklusion in Open Source

Red Hat hat sich verpflichtet, problematische Sprache in unserem Code, unserer Dokumentation und unseren Web-Eigenschaften zu ersetzen. Weitere Einzelheiten finden Sie in Red Hat Blog.

Über Red Hat

Wir liefern gehärtete Lösungen, die es Unternehmen leichter machen, plattform- und umgebungsübergreifend zu arbeiten, vom zentralen Rechenzentrum bis zum Netzwerkrand.

Theme

© 2025 Red Hat