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

88
Visualizações
Lazy fields always loaded

I have classes with a many-to-one relationship. When I query for them using Criteria.list, the lazy fields are populated.

public class SE {

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "mSe")
    private List<RS> mRs;
}

public class RS {

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "my_join_id")
    private SE mSe;
}

...

Criteria criteria = session.createCriteria(SE.class);    
List<SE> myObjects = criteria.list();

// SE objects have lazy list populated. why?

How do I prevent the lazy fields from being loaded?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

How do you know it is populated?

If you are looking with your debugger, it is a normal behavior because the debuger do a lot of stuff and most of the time call the getter to have a string representation of the instance. Since the getter is called, the lazy loading is triggered.

What you can do to ensure it is really lazy loaded is remove your @Transactional annotation, and you should have an error when rying to access SE in the debugger.

over 4 years ago · Santiago Trujillo Relatório
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