Search code examples
jpaeclipselink

JPA multiple entities one table/view


I have been tasked with fixing a number of bugs on existing application that makes use of JPA (EclipseLink).

In this application it common for there to be multiple entities that indirectly share the same table via SQL views. As an example, I might have a entity called TEmployeeInfo and another entity called VActiveEmployeeInfo. While the first maps to a table directly, the second maps to a view of the same table as the first.

This seems like it would cause issues with caching as any updates using the first entity (table) would not be immediately available in the second (view).

Are my suspicions correct?

If so, what are some possible steps to correct this short of refactoring a large portion of the application?


Solution

  • If the same rows are mapped twice, then the cache can become stale if the objects are updated. You can have both classes use the real table, or perhaps use inheritance.

    Otherwise, you can disable the shared cache of this class.

    http://wiki.eclipse.org/EclipseLink/FAQ/How_to_disable_the_shared_cache%3F