1

I'd like to create a JPA second-level cache for use with an entity's secondary key. As an example let's use State (as in California) and I'd like to use it's abbreviation ("CA") as the cache key. How do I set this up?

I'm using Infinispan with Wildfly 8. Do I have to work with Infinispan directly? If so, how do I define the cache (in the persistence.xml ?) and how do I access it in my code?

Gary Kephart
  • 4,860
  • 5
  • 39
  • 52

1 Answers1

2

You may want to look at @NaturalId.

It seems to utilize the second-level cache as well.

Community
  • 1
  • 1
Dragan Bozanovic
  • 23,102
  • 5
  • 43
  • 110
  • That looked promising until I read more and saw that it's specific to Hibernate and not part of JPA. Looks like it works using "session.byNaturalId(...)" but JPA's EntityManager does not have a corresponding method. – Gary Kephart Aug 26 '15 at 18:17
  • You can always get the `Session` from the `EntityManager`: `entityManager.unwrap(Session.class)`. More details [here](http://stackoverflow.com/questions/4148231/how-can-i-get-the-session-object-if-i-have-the-entitymanager). – Dragan Bozanovic Aug 26 '15 at 18:28