I tried to enable subselect fetching on a many-to-one association and got this message:
org.hibernate.AnnotationException: Use of FetchMode.SUBSELECT not allowed on ToOne associations
The documentation, however states that:
19.1.6. Using subselect fetching
If one lazy collection or single-valued proxy has to be fetched, Hibernate loads all of them, re-running the original query in a subselect. This works in the same way as batch-fetching, without the piecemeal loading.
If I understand this correctly the many-to-one should be the single-valued proxy that it is talking about there. What I'd like to do is something simple like map a Person to a Login as many-to-one such that each login has exactly one person. Then I would like to do:
select login FROM Login as login
In which the person association would be loaded as a proxy for later lazy-fetching.
When I do login.getPerson() I would like for ALL person proxies to get loaded at once with a subselect. That is ... something like...
select * from person where id in (select personId from login);
Isn't this what Subselect fetching is supposed to do for me? Why is it not available for Many-to-one and one-to-one???
|