john miran
john miran

Reputation: 393

Cannot change the type of an instance of parent A to subclass B In the JPA join table strategy

We use Eclipselink-2.6 with wildfly-8 server in a JavaEE7 application.

we have three JPA entities A, B, and C.

B and C extend A.

In order to change the type of an object "myObjectId" A to B, we try to:

1- Change the dtype value from "a" to "b" in Table "A" for the instance "myObjectId" using the criteria query.

2- Create a new row in the table "B" in the database for the same id "myObjectId" also with a criteria query.

3- Clearing the cache by evictAll as well Entitymanger using clear functions.

After, when I tried to find all data of type B, the object "myObjectId" came in the list but with type A!

After restarting wildfly server and call findAll, therefore, the data came with type B!

why myObjectId didn't change its type even if the first and the second level cache was cleared!?

Upvotes: 0

Views: 39

Answers (1)

Chris
Chris

Reputation: 21145

See https://wiki.eclipse.org/EclipseLink/Examples/JPA/Caching

Essentially EclipseLink maps the JPA cache eviction call to its own invalidation logic, which seems to be keeping a reference to the object using a soft reference so that object identity is maintained. This prevents A1->B1->A1' from happening on cycles with lazy relationships.

Try calling ((JpaEntityManager)em.getDelegate()).getServerSession().getIdentityMapAccessor().initializeAllIdentityMaps() as suggested in the doc and then reading in the changed class.

Upvotes: 1

Related Questions