[id='jpa-cache-store_{context}']
= JPA cache stores

JPA (Java Persistence API) cache stores, `JpaStore`, use formal schema to persist data.

Other applications can then read from persistent storage to load data from {brandname}.
However, other applications should not use persistent storage concurrently with {brandname}.

When using JPA cache stores, you should take the following into consideration:

* Keys should be the ID of the entity. Values should be the entity object.
* Only a single `@Id` or `@EmbeddedId` annotation is allowed.
* Auto-generated IDs with the `@GeneratedValue` annotation are not supported.
* All entries are stored as immortal.
* JPA cache stores do not support segmentation.

[NOTE]
====
You should use JPA cache stores with embedded {brandname} caches only.
====

[discrete]
== JPA cache store configuration

.XML
[source,xml,options="nowrap",subs=attributes+,role="primary"]
----
include::xml/persistence_jpa_store.xml[]
----

.ConfigurationBuilder
[source,java,options="nowrap",subs=attributes+,role="secondary"]
----
include::code_examples/ConfigJpaStore.java[]
----

[discrete]
== Configuration parameters

[%header%autowidth,cols="1,1,1",stripes=even]
|===
|Declarative |Programmatic |Description
|`persistence-unit`
|`persistenceUnitName`
|Specifies the JPA persistence unit name in the JPA configuration file, `persistence.xml`, that contains the JPA entity class.

|`entity-class`
|`entityClass`
|Specifies the fully qualified JPA entity class name that is expected to be stored in this cache. Only one class is allowed.
|===

[role="_additional-resources"]
.Additional resources
* link:{configdocroot}infinispan-cachestore-jpa-config-{schemaversion}.html[JPA cache store configuration schema]
* link:{javadocroot}/org/infinispan/persistence/jpa/JpaStore.html[JpaStore]
* link:{javadocroot}/org/infinispan/persistence/jpa/configuration/JpaStoreConfiguration.html[JpaStoreConfiguration]
//Community only
ifdef::community[]
* link:https://github.com/infinispan/infinispan/blob/main/persistence/jpa/src/test/java/org/infinispan/persistence/jpa/configuration/JpaConfigurationTest.java[JPA Cache Store test]
* link:https://github.com/infinispan/infinispan/blob/main/persistence/jpa/src/test/resources/config/jpa-config.xml[JPA Cache Store test configuration]
endif::community[]
