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