Skip to content

Support binding embeddables and associations using compound or foreign keys in CTE’s #571

@jwgmeligmeyling

Description

@jwgmeligmeyling

Description

I am facing a couple of rarities with CTE's that have a @ManyToOne relationship. First of all, when I do something like this: bind("ref").select("entity.someMapping"), all columns of someMapping are bound in the CTE, even though they are unused. This can be worked around with by mapping to the id instead, like so: bind("ref").select("entity.someMapping.id"), which works, even without changing the type of the field, but has some other quirks: in the final select query, the reference will always be lazy loaded (i.e. only the id column). Specifically adding the fetch join to the criteria builder is ignored. The effective query remains the same.

Expected behavior

The expected behaviour is that the CTE only selects the required columns, and that it is possible to optionally fetch join these fields in the final result set.

Actual behavior

Either the fields have to be "fetch joined" in the CTE part already (leading to an unnecessarily complex CTE query), or it is not possible to fetch join these queries at all (adding fetch joins to a CTE root seems to be ignored).

Steps to reproduce

Workaround

A workaround is to map the id and referenced entity separately, but to a different column. Then in the CTE you bind the column through the id field, and in the final query you can fetch join the entity field.

Environment

Version:
JPA-Provider:
DBMS:
Application Server:

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions