Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

95
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda