2

This is how my domain looks:

public class Template implements Serializable {
    private static final long serialVersionUID = 1L;    
    @OneToOne(cascade=CascadeType.ALL)
    private FieldConfig fieldConfig;
}

public class FieldConfig implements Serializable {
    private static final long serialVersionUID = 1L;

    @OneToMany(cascade= CascadeType.PERSIST)
    @JoinColumn(name = "fieldConfigId")
    private Set<Field> fieldSet;
}

I want to achieve if I load a template from the db that automatically the fieldConfig is loaded and the fieldSet of that fieldconfig.

my current JPQL:

TypedQuery<Template> query = em.createQuery("SELECT t from Template t LEFT JOIN FETCH t.fieldConfig"
                + " fconfig LEFT JOIN FETCH fconfig.fieldSet where t.id = :id", Template.class);

my exception:

Internal Exception: NoViableAltException(80@[()* loopback of 477:9: (node= join )*])
Exception Description: Syntax error parsing the query [SELECT t from Template t LEFT JOIN FETCH t.fieldConfig fconfig LEFT JOIN FETCH fconfig.fieldSet where t.id = :id], line 1, column 55: unexpected token [fconfig].

Any thoughts on creating such a query?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Frédéric Gobert
  • 188
  • 1
  • 2
  • 8

1 Answers1

3

You cannot use an alias on a join fetch in JPQL, this is disallowed by the spec.

EclipseLink does allow nested join fetch through the query hint,

"eclipselink.join-fetch"="t.fieldConfig.fieldSet"
James
  • 17,965
  • 11
  • 91
  • 146