I found out what the problem is:
I you want to use Hibernate.initialize() to load your lazy loaded collections, it is a bad idea to set @Fetch(FetchMode.SUBSELECT) for these collections.
(In my case the subselect was an relict from the first tests using eager loading).
To illustrate what happens, here the generated SQL Statements (the very last line of each code block shows the difference)
with @Fetch(FetchMode.SUBSELECT):
Code:
Hibernate: select revs0_.modelId as modelId1_, revs0_.id as id1_, revs0_.id as id7240_0_, revs0_.version as version7240_0_, revs0_.uuid as uuid7240_0_, revs0_.name as name7240_0_, revs0_.description as descript5_7240_0_, revs0_.number as number7240_0_, revs0_.modelId as modelId7240_0_ from _Revision revs0_ where revs0_.id = (select rev.id from _Revision rev where rev.modelId = ? and rev.number = (select max(r.number) from _Revision r where r.modelId = ?)) and revs0_.modelId
in (select model0_.id from _Model model0_)
without @Fetch(FetchMode.SUBSELECT), defaults to FetchMode.JOIN:Code:
Hibernate: select revs0_.modelId as modelId1_, revs0_.id as id1_, revs0_.id as id6456_0_, revs0_.version as version6456_0_, revs0_.uuid as uuid6456_0_, revs0_.name as name6456_0_, revs0_.description as descript5_6456_0_, revs0_.number as number6456_0_, revs0_.modelId as modelId6456_0_ from _Revision revs0_ where revs0_.id = (select rev.id from _Revision rev where rev.modelId = ? and rev.number = (select max(r.number) from _Revision r where r.modelId = ?)) and revs0_.modelId
=?
The consequence when using FetchMode.SUBSELECT is, all revision collections of all models are getting initialized, no the one requested.
I don't know if this behavior is defined or not, at least I should be mentioned in the documentation (if it is, I didn't find it).
Maybe in section "19.1.4. Initializing collections and proxies".