| FetchMode.SUBSELECT is ignored by the algorithm that builds a query from EntityGraphs as it only ever builds a single query and so must load everything with that single query. Because of this, the entitygraph implementation as it is now, is not usable when doing multiple joins though OneToMany or ManyToMany mappings. Any non-trivial scenario will require multiple queries to get reasonable performance. Instead annotate OneToMany or ManyToMany with FetchMode.SUBSELECT and execute a simple query without the joins. Then load the OneToMany or ManyToMany fields using hibernate's lazy loading (accessing the child field directly or calling Hibernate.initialize() on the child will do this provided you still have a session). We ended up writing a reflection based algorithm which does this for our own implementation of EntityGraph but do not pass this to hibernate at any stage. |