Wie kann ich @SubSelect mit @inheritance und postgres Version <16 zum Laufen bringen?
Posted: 25 Feb 2025, 09:34
Ich verwende Hibernate -Erbe mit @Inheritance und möchte @SubSelect anstelle von @table wie folgt verwenden:
Der Fehler tritt nicht mit demselben @SubSelect auf, aber ohne Vererbung.
Ich verstehe, dass das Problem das Problem Die Verwendung der Vererbung führt zu einer Abfrage unter Verwendung von Union All wie diese (vereinfacht): Klausel, war aber nur in der Lage, Syntaxfehler um die Klammern zu erhalten. und @inheritance arbeiten, aber ich nehme an, sie haben keine Postgres verwendet. Meine Alternative wäre es, die Unterauswahl als Ansichten zu definieren und sie mit @table zu verweisen, aber es wäre schön, wenn das nicht notwendig wäre.
Code: Select all
@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public abstract class Parent { ... }
< /code>
@Entity
@Subselect("select a,b,c from entity_a")
public class EntityA extends Parent { ... }
< /code>
@Entity
@Subselect("select a,b,c from entity_b")
public class EntityB extends Parent { ... }
< /code>
This does not work and I get the error: org.postgresql.util.PSQLException: ERROR: subquery in FROM must have an alias
Der Fehler tritt nicht mit demselben @SubSelect auf, aber ohne Vererbung.
Ich verstehe, dass das Problem das Problem Die Verwendung der Vererbung führt zu einer Abfrage unter Verwendung von Union All wie diese (vereinfacht):
Code: Select all
select *
from (select a, b, c
from entity_a)
union all
select *
from (select a, b, c
from entity_b)
< /code>
I tried adding an alias in the @Subselect
Code: Select all
@Subselect("(select a,b,c from entity_a) as x")
< /code>
@Subselect("(select a,b,c from entity_a) x")
< /code>
I also read that Postgres 16 made subquery aliases optional, but unfortunately I have to use Postgres 13 for the time being.
Here a person made @Subselect