I have a huge number of entities i need to load from the DB, i have a query like this
FROM ${entityName} x WHERE x.id IN :ids
the above generates SQL queries like this: ... where EntityName.id in (? , ? , ? , ? , ? , ? , ? , ? , ...)
This is incredibly slow for large ids
sets. Multiple posts here have suggested instead to run an IN VALUES
query like this:
... where EntityName.id in (VALUES (?) , (?) , (?) , (?) , (?) , (?) , (?) , (?) , ...)
Here is my Java:
List<T> result = entityManager.createQuery(queryString, queryEntity)
.setParameter("ids", batch)
.getResultList()
Wondering how i can get hibernate to do that?
Do i need to specify that in the HQL somehow?
I tried this not expecting it to work, and it didn't.
SELECT x FROM ${entityName} x WHERE x.id IN (VALUES :ids)
Is this even possible in HQL, or do i need to write a native query?