Hi i have the following structure of object
Grid
---Row (first level has a parentRow = null)
------SubRows ... (which is actually a Row that its parent Row is not null)
------Cells
---Cells
as you can se i have a grid that has one or more rows, and each row has one or more cells. and this row may have one or more subrows which also have one or more cells.
i want to write a query that loads the entire structure of the grid in one select, using joins. if i am writing for one level supposing that there are no subrows i would do something like this:
from Grid grid left join fetch grid.rows r left join fetch r.cells where grid.id = :id
which will load the grid object and the collection of rows and the collection of cells for each row.
however i want to load also the subrows and their corresponding cells, so i am using something like this:
from Grid grid left join fetch grid.rows r left join fetch r.cells left join fetch r.childRows where grid.id = :id
but when i do the following:
grid.getRows().iterator().next().childRows.iterator().next().getId()
I get an exception of type java.util.NoSuchElementException.
i don't want to make the fetching strategy in the class mapping, i want to load all the grid hirearchy in one query using HQL.
any help ??
thanx in advance.
|