Quote:
Are you talking about managed entities?
No, it are just POJO's, but 'deep nested' POJO's: in the example I gave, a user has a Set of Usergroups and Usergroups have themselves Sets of translations and so on (so basically all one-to-many relations). Next to the Set of UserGroups, a User consists also of a Set of UserRoles and a Set of Languages and so on.
So, what I really want to do, is to load one or more users from the database, based on some criteria, with in some cases all the data (the userGroups with translations, the userRoles,...) ideally in one big createCriteria-statement.
I know there are two working options to do so:
1. Define all relations in the mapping as lazy="false". But, I don't want to do that, because I do not always want all related data.
2. create the query and get all related data (for the one-to-many relations) with left join fetch (HQL) or setFechtMode("...", FetchMode.Join) (criteria query). But that doesn't seem as an option to me either, because with too much left joins on one-to-many relations, we would have to deal with the cartesian product problem (see for example
http://www.hibernate.org/hib_docs/reference/en/html/queryhql.html). In my example, a fetch join on all relations could still work, but I have other examples where we have objects with a lot more one-to-many relations and several of them again with one-to-many relations. Sot in that case this isn't an option either.
That's why I tried to use the setFetchMode("...", FetchMode.SELECT). In the documentation it is mentioned that this also gets the related data, but in a seperate query and that is exactly what I wanted. But apparently, this doesn't work: the related data is not loaded.
So my question is: how to really load the related data in a seperate query? Do I forget something the way I'm doing it? The relevant piece of code and mapping is in my first post.
Quote:
Do you want the data or not? In some way it most be transported from DB to you entities; if you explaing when and how much (data) we could help to define that.
So, yes I want the data. And in some cases it is a lot of data with a lot of nested one-to-many relations. I thought of using seperate queries for all one-to-many relations of the first level (so for example the userGroups of the user) and a left join fetch on the relations of the second level (so for example the translations of the userGroups).