I have a class A and sub-classes B and C which have different properties. How can I do something like: a from A a where ( a.class = B and a.specific-property-of-b = "y") or (a.class = C and a.specific-property-of-c ="z")
Is it possible to get hibernate understand that when it's an instance of a certain class then it can access the specific properties of it or is it impossible to do something like that and I have to do:
a from A a where a.id in (select b.id from B b where b.specific-property-of-b = "y") or a.id in (select c.id from C c where c.specific-property-of-c = "z")
Thank you
You do it as you suggested:
select a from A a
where (a.class = B and a.specificPropertyOfB = 'y')
or (a.class = C and a.specificPropertyOfC = 'z')
The only thing that won't work correctly (in my experience) is if you define two persistent fields with the same name in both subclasses.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With