Search code examples
hibernatejpaeclipselink

EclipseLink what is the equivalent of the NaturalID concept from Hibernate


I would like to use EclipseLink as a persistence provider and if possible even use JPA annotations, only. I found the following question here on stackoverflow, which I think contains the wrong answer marked as "answered":

JPA equivalent to Hibernate's @NaturalId

Why is it wrong? Because simply adding a unique constraint to a field/column is NOT what naturalID provides as the main benefit in the hibernate world. "@naturalID" provides very important Level 2 cache capabilities, which I would like to use in the future as well. See more details in the following stackoverflow answer:

What is a natural identifier?

Any suggestions/ideas? From the documentation in EclipseLink I could see anything that looks similar... .


Solution

  • @cacheindex and it's array equivalent helps you achieve L2 hits even if querying by natural (business) keys and not just @id.