Consider three entities: Shape, Circle and Rectangle.
Circle and Rectangle are inherited from abstract class Shape using @Inheritance( strategy = InheritanceType.JOINED ). All three entities have persistent fields that are mapped to respective three database tables: shape, circle and rectangle. ID field is held in Shape entity. Circle and Rectangle use ID of the root entity Shape (via @PrimaryKeyJoinColumn).
PRECONDITIONS:
1. Let's there is a single Circle entity in the database with ID=1 and no Rectangles.
2. Let's this Circle entity is already in L2 cache.
SCENARIO 1:
1. Start a new session. This session does not have any entities in it's own cache yet.
2. Obtain a Rectangle with ID=1: session.get( Rectangle.class, 1L ) => returns Circle with ID=1. That's obviously wrong, because Rectangle is not a subclass or a superclass of Circle.
SCENARIO 2:
1. Check whether L2 cache has Rectangle with ID=1: sessionFactory().getCache().containsEntity( Rectangle.class, 1L ) => returns true, however should return false.
TestCase is in attachment.
|