| Hi Christian, thanks for your reply. I just ran a test with the above suggestion and got the following results: 1. If I do not specify WHERE TYPE(E) = B, the query returns all results to me of all subclasses. 2. If I add the WHERE clause to the query, doing this (had to rewrite the test, so some of the properties might be different):
TypedQuery<Holder> q = em.createQuery("SELECT h from HibernateTest$Holder h LEFT JOIN FETCH TREAT (h.list AS HibernateTest$B) e where TYPE(e) = HibernateTest$B", Holder.class);
I do get the correct result, however I am still joining on all subclasses, like:
Hibernate: select hibernatet0_.holderId as holderId1_3_0_, list1_.id as id1_0_1_, list1_.subclassId as subclass2_0_1_, list1_1_.prop2 as prop1_2_1_, list1_2_.prop1 as prop1_1_1_, case when list1_1_.id is not null then 1 when list1_2_.id is not null then 2 when list1_.id is not null then 0 end as clazz_1_, list1_.subclassId as subclass2_0_0__, list1_.id as id1_0_0__ from HibernateTest$Holder hibernatet0_ left outer join HibernateTest$A list1_ on hibernatet0_.holderId=list1_.subclassId left outer join HibernateTest$C list1_1_ on list1_.id=list1_1_.id left outer join HibernateTest$B list1_2_ on list1_.id=list1_2_.id where case when list1_1_.id is not null then 1 when list1_2_.id is not null then 2 when list1_.id is not null then 0 end=2
So, I believe the treat works very similar to the type query in the original post, however there is still a lot of joining going on. I think it might be a nice improvement to performance to optimise the behaviour of the inheritance queries. |