After updating an application that still uses XML mapping definition from 5.2 to 5.4 some requests suddenly started to take 10 times or even more time.
If figured out that the 2nd level caching was no longer working for some classes. Those classes are using the unionsubclass mapping. Even multiple simple session.get(unionsubclass, id) (in multiple sessions) don't fetch the entity from the 2nd level cache anymore but always hit the database. But where it hurts most is if these entities are reference from a cached collection. In this case the performance is much worse than without any caching at all as each cache miss (which is everytime now) hits the database for each entity with the ID instead of selecting them all with a single select using the foreign key.
After switching back to 5.2.17 the caching worked again as expected. I know that there were some changes regardging enabling caching on different levels in class hierarchies. But I didn't find anythign that says that the existing definitions must be changed and you cannot define any caching on the unionsubclass level anyway so I suppose this is a bug. When using annotations and MappedSuperclass it works as expected.
The attached test case inserts 2 entities, one using HBM and unionsubclass and the other annotations and mappedsuperclass. Then it fetches them using session.get() in 3 separate sessions.
When you run it with 5.2.17 you get the follow SQL
So there is no select at all. But when you run it with 5.4 you get this
and the HBM version is fetched 3 times from the database