The next query should return about 800 objects. The problem is that hibernate actually executes 800 requests to get all of them. It seems that it performs one request for identifiers, and then performs one request for each object to obtain specific data about the object. It takes more than 60 seconds to return this request.
List<AUser> result = em.createQuery("FROM AUser where company=:companyId")
.setParameter("companyId",company.getId())
.getResultList();
Native query is much faster.
List<AUser> result = em.createNativeQuery("select a.* FROM AUser a where a.company=:companyId")
.setParameter("companyId",company.getId())
.getResultList();
The above request takes less than one second to return.
Why is the difference?
source
share