= JPA Cache Store Usage Example

The following is an example for using a JPA cache store:

. Define a persistence unit "myPersistenceUnit" in `persistence.xml`.
+
[source,xml,options="nowrap",subs=attributes+]
----
include::config_examples/persistence_unit_example.xml[]
----
+
. Create a user entity class.
+
[source,java]
----
include::code_examples/PersistenceUserEntityClass.java[]
----
+
. Configure a cache named "usersCache" with a JPA cache store.
+
Then you can configure a cache "usersCache" to use JPA Cache Store, so that when you put data into the cache, the data would be persisted into the database based on JPA configuration.
+
[source,java]
----
include::code_examples/PersistenceJpaCacheStore.java[]
----

* Caches that use a JPA cache store can store one type of data only, as in the
following example:
+
[source,java]
----
include::code_examples/CacheJpaStore.java[]
----

* The `@EmbeddedId` annotation allows you to use composite keys, as in the
following example:
+
[source,java]
----
include::code_examples/EmbeddedIdExample.java[]
----
