StatefulPersistenceContext. getEntry( Object entity) returns the EntityEntry that has been cached in the enhanced ManagedEntity, so we need to check that the cached EntityEntry has been added by the current PersistenceContext or a different PersistenceContext.
But this is actually the entire crux of the problem. There is no way to check that. We used to have this and completely changed it based on the perf team's findings....
Would it be better represented by a Map , so ManagedEntity.$$_hibernate_getEntityEntry(PersistenceContext persistenceContext) would return the correct EntityEntry object. This would be an API change though, so not backward compatible.
But this is exactly what we had before - a Map based solution. Except before at least that was limited to one Map per Session/PersistenceContext. Here, what you suggest, would require a Map per entity instance. Ugh. I can't see how that performs anything but worse than what we used to have. The bottom line is that we need some form of mapping to describe "here is the persistence state (status, etc) for a given entity in association with this given Session/PersistenceContext". And we really do not have that today. What we have today since implementing the perf team's recommendation is "here is the persistence state (status, etc) for a given entity" - the entire piece about "in association with this given Session/PersistenceContext" is missing. I get that maintaining this Map on the entity (ManagedEntity) will "work". I think the question really is about performance oddly enough |