I have an entity called Foo. It has a nullable many-to-one association to Bar. Bar has a non-nullable many-to-one association to Baz.
My goal is to grab all Foo entities and eagerly fetch their Bar associations and, for those foo where foo.bar is non-null, eagerly fetch foo.bar.baz.
Is this possible? The following both cause hibernate to throw a NullPointerException inside its query engine:
select f from Foo f left join fetch f.bar left join fetch f.bar.baz
select f from Foo f left join fetch f.bar.baz
Now, this works:
select f from Foo left join fetch f.bar
But that doesn't eagerly fetch f.bar.baz for those f with non-null bar.
You need to alias bar
in your query:
select f from Foo f
left join fetch f.bar b
left join fetch b.baz
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.