[hibernate-dev] Natural ids and inheritance

Steve Ebersole steve at hibernate.org
Tue Feb 28 11:59:46 EST 2012


Another discrepancy between hbm.xml and annotations currently is the 
definition of natural ids.  hbm.xml only allows natural ids to be 
defined on the root entity, annotations allow it to be defined on any 
level of the hierarchy, even across classes.

We need to decide what we want to support.  2 things to consider here are:
1) whether we limit @NaturalId to only root entity meta (and maybe 
@MappedSuperclass for root entities)
2) if we do not limit, what @NaturalId spread across a hierarchy "means"

In the second point, consider:
class A
     @NaturalId
     key1

class AA extends A
     @NaturalId
     key2

Personally I vote for limiting @NaturalId to the root entity.  This 
allows caching to work just like it does for identifiers.

-- 
steve at hibernate.org
http://hibernate.org




More information about the hibernate-dev mailing list