I have to disagree here. I've come across this issue a number of times and haven't been able to solve it elegantly.
Here is a class hierarchy, mapped using joined-subclass:
Code:
public class Person {
List<PhoneNumber> phoneNumbers;
List<PostalAddress> postalAddresses;
String firstName;
String lastName
...
}
public class User extends Person {
String username;
String password;
Date lastLoginTimestamp;
Date passwordExpirationTimestamp;
...
}
A lot of systems I have written require address book functionality. As such, an address book has a collection of Person objects.
During runtime though, I want to cache all
Users for efficient access, not all Persons. There could be orders of magnitude more Person objects than Users (since people in an address book don't need to be a user, and most arent).
I only want to cache Users for efficient access, not all Persons, which, due to pure quantity, would force cache cleanup/maintenance too often.
I have many more concrete reasons why its convenient to cache instances of only a subclass, and not all instances in a class hierarchy.
Is this not reason enough to enable the <cache> element within <subclass> and <joined-subclass> mappings?