Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

192
Visualizações
Limit the set of selected fields to those of the target subclass

I'm using single table inheritance, one parent entity:

@Entity
@Table(name = "parent")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "type")
public class Parent {
  // ...
}

and two child entities:

@Entity
@DiscriminatorValue("child1")
public class Child1 extends Parent {
  @Column(name = "child1_property")
  private Integer child1Property;
  // ...
}
@Entity
@DiscriminatorValue("child2")
public class Child2 extends Parent {
  @Column(name = "child2_property")
  private Integer child2Property;
  // ...
}

Now, if I query (HQL) directly from Child1 entity:

from Child1

it will generate an SQL that selects only the columns from Parent entity plus Child1 entity. If I select from Parent entity using a where type='child1'

from Parent p where type(p)='child1'

it will return only Child1 entities but the SQL query selects all columns from Parent, Child1 and Child2. Is there a possibility to query from Parent entity use the discriminator column (i.e. limit only to Child1 entities) and get a specific SQL query, i.e. that will select only columns from Parent and Child1.

over 4 years ago · Santiago Trujillo
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda