I use Hibernate and want to query for entities by their natural identifier. However, it seems not to be possible to have natural ids on subtypes. I have two classes A and B where B extends A:
class A {
long id;
}
class B extends A {
String naturalId;
}
A
is mapped in Hibernate with its own identifier. B
is mapped as joined subclass. However, it is not possible to map the natural identifier of B
in Hibernate because the mapping of B
is a subclass mapping.
Why is it not possible to have a natural identifier on the subclass
B
? Note that I don't want Hibernate to generate my database schema, I just want to have natural ids for fast cache hits.Is there a way/a best practice to have natural ids on subtypes for fast second level cache querying?
- Is this still possible when natural ids might get updated (change) in rare circumstances and the cache has to be maintained in a clustered Java EE environment?