I'm trying to use EntityGraphs or JPQL to create 1 select instead of many small (sub) selects. However, there sub entities are loaded in extra selects. Example:
@NamedEntityGraph( name = "All",
attributeNodes = {
@NamedAttributeNode( value = "bars", subgraph = "subgraph.foobars") },
subgraphs = {
@NamedSubgraph( name = "subgraph.foobars",
attributeNodes = {
@NamedAttributeNode(value = "fooBars", subgraph = "subgraph.foobar"),
@NamedAttributeNode( "mqttEndpoints" ) } ),
@NamedSubgraph( name = "subgraph.foobar",
attributeNodes = {
@NamedAttributeNode( "name" ) } ) })
public class Foo {
@OneToMany( fetch = FetchType.LAZY )
private Set<Bar> bars = Sets.newHashSet();
}
public class Bar {
@OneToMany( fetch = FetchType.LAZY )
private Set<FooBar> fooBars = Sets.newHashSet();
}
public class FooBar {
String name;
}
Use EntityGraph or JPQL is not working
"SELECT DISTINCT f FROM foo f"
+ " LEFT JOIN FETCH f.bar bars "
+ " LEFT JOIN FETCH bar.fooBars foobars "
+ " WHERE t.id =:id " )
Log
SELECT ...
FROM foo t1
LEFT OUTER JOIN bars t0 ON (t0.bar_id = t1.id)
SELECT name
FROM foobar
WHERE ...
For all subentities there is select
If i use queryhints then it works without subselect so what is wrong? https://www.eclipse.org/eclipselink/documentation/2.5/jpa/extensions/q_left-join-fetch.htm
With hibernate this works well.