Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

87
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!