|
So here is what we have atm wrt Session#get:
-
When match found in session cache we effectively return null. Technically we return a marker because get's options state that is in fact can return nulls. See DefaultLoadEventListener#loadFromSessionCache and the INCONSISTENT_RTN_CLASS_MARKER branch in its caller for details.
-
When match found in L2 cache, afaict CCE was always the result in the "wrong class" case.
-
When hitting the database we return null because we get back an empty ResultSet because the discriminator is included. I verified this happened in the older Loader code too; it was not just the move to LoadPlans.
So definitely there is an inconsistency here. The previous solution is still not correct though. What should happen is that either we consistently throw WrongClassException, or we consistently return null (when possible).
TBH, I just do not see the benefit of simply returning null here. But I'll let Guillaume Smet convince me 
|