[hibernate-dev] Natural ids and inheritance

Steve Ebersole steve at hibernate.org
Thu Mar 1 13:13:13 EST 2012


Thats not legal definition of natural ids.  Only the *root entity* can 
define natural ids, here A.


On Thu 01 Mar 2012 11:11:47 AM CST, Demetz, Guenther wrote:
> Hi Steve,
>
>>> Caching should be using the root persister of the hierarchy for cache keys.
>
> Hm,  it probably depends on how you fixed HHH-7129.
>
> Is following hierarchy allowed after HHH-7129 ?
>
> @Entity
> class A {
>    @Id
>    int id;
> }
>
> @Entity
> class Subclass1 extends A  {
>    @NaturalId
>    String name;
> }
>
> @Entity
> class  Subclass2 extends A  {
>    @NaturalId
>    String card;
> }
>
> If it is still allowed, then caching
>
> session.bySimpleNaturalId(SubClass2.class).load("g");
>
> should't use the root persisterA, it should use persisterSubclass2, otherwise
>
> session.bySimpleNaturalId(SubClass1.class).load("g");
>
> would overwrite the previous cached entry, right?

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



More information about the hibernate-dev mailing list