abstract MyBean with @Inheritance ( strategy = InheritanceType.SINGLE_TABLE )
MyBeanWithA extends MyBean and add a OneToOne eager relation with ABean (inverse side)
MyBeanWithB extends MyBean and add a OneToOne eager relation with BBean (inverse side)
ABean with a OneToOne eager relation with MyBeanWithA (right side)
BBean with a OneToOne eager relation with MyBeanWithB (right side)
Foreign keys on db need to be on ABean and BBean.
I need always to access MyBeanWithA when I access ABean.
I need always to access ABean when i access MyBeanWithA.
The same is for BBean and MyBeanWithB.
What I'm not capable to do is have an entity correctly loaded with his relation using polimorphism.
Here's the code (it isn't so beautiful but it's only demonstrative)
As you can see versions A and B are practically the same (much copy/paste )
Running this all (without log just to see) I get this (complete log in attach, try_1.log ):
I can't uderstand why using polymophism for MyBeanWithB I get a null reference, just for control loading MyBeanWithB without polymophism i get BBean correctly loaded
Looking for SQL it seems that BBean isn't considerated:
/* load my.entity.MyBean */ select
mybean0_.myBean_id as myBean2_2_2_,
mybean0_.bean_name as bean1_2_2_,
abean1_.id as id0_0_,
abean1_.myBean_id as myBean2_0_0_,
mybeanwith2_.myBean_id as myBean2_2_1_
left outer join
left outer join
Instead setting relations on MyBeanWithX (i've changed optional from false to true)
The result is even worse in SQL BBean is now consierated but beans reference are null both for MyBeanWithA and MyBeanWithB (complete log in attach, try_2.log )
You have any suggestions?
subject: Hibernate InheritanceType.SINGLE_TABLE with different eager OneToOne relations