So I have three entities. A FormCollection contains multiple Form. The Form is created from a template and thus has also a many-to-one relation to FormTemplate.
@Table(name = "form_collection", schema = "public")
public class FormCollectionDO extends BaseAuditableDO {
@OneToMany(mappedBy = "formCollection")
@OrderBy("formTemplate.templateId") //throws error
private List<FormDO> forms = new ArrayList<>();
}
@Table(name = "form", schema = "public")
public class FormDO extends BaseAuditableDO {
@NotNull
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "form_template_id")
private FormTemplateDO formTemplate;
}
@Table(name = "form_template", schema = "public")
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
public class FormTemplateDO extends BaseDO {
@Column(name = "template_id", nullable = false)
@NotNull
private Long templateId;
}
@OrderBy("formTemplate.templateId") throws an error:
o.h.engine.jdbc.spi.SqlExceptionHelper : ERROR: missing FROM-clause entry for table "formtemplate"
@OrderBy("formTemplate.id") works fine. The id comes from the abstract class BaseDO. Why does it not work with any of the fields from the FormTemplateDO class?