If having a class Kpi with a collection Columns, and doing a query like this: "select k.Id where Kpi k left join fetch k.Columns where k in (:kpis)" the correct k.Ids are returned but only the ks which have a non-empty collection Columns have their collection initialized. The ones with empty collections will trigger a new select when accessed.
I've tried this with other classes than Kpi and have got the same result of not getting the collection initalized.
This issue cause quite a bit of problem for me on my current project as I have many collections attached to Kpi.
The query with c.Id} It does not initialize nor empty, nor not empty collections.
The query with c does the initialization in both cases. I don't know if it should maintain identity between c.Id and a company itself.
Oskar Berggren
October 11, 2014 at 4:25 PM
I read through the referenced forum post, and get the impression that this is indeed a bug. Or at least missing part of a feature.
Didn't try it myself, but if "select c.Id from Company c left join fetch c.Departments" will in fact fetch the Id column and all Department columns and initialize non-empty Department collections of any already loaded Company instances, then it seems reasonable that it should also initialize empty Department collections.
Alex Zaytsev
October 11, 2014 at 11:44 AM
Probably needs to be closed as not an issue
Alex Zaytsev
October 11, 2014 at 11:43 AM
Both tests works with c instead of c.Id.
Alex Zaytsev
October 11, 2014 at 11:41 AM
Test case is invalid. The second test becomes green if select company c and not c.Id:
Problem orginally described in this thread: http://forum.hibernate.org/viewtopic.php?t=981220
If having a class Kpi with a collection Columns, and doing a query like this:
"select k.Id where Kpi k left join fetch k.Columns where k in (:kpis)"
the correct k.Ids are returned but only the ks which have a non-empty collection Columns have their collection initialized. The ones with empty collections will trigger a new select when accessed.
I've tried this with other classes than Kpi and have got the same result of not getting the collection initalized.
This issue cause quite a bit of problem for me on my current project as I have many collections attached to Kpi.