How do I fetch 2 million records from database ?
Question 2 :
How do I remove duplicate values in one of the fields? Can I use hashset?
posted 4 years ago
I suppose it depends on how much memory you have, and how big the rows are.
You could just query them as normal, assuming you have enough memory, but it would probably be better to page them, or use a cursor to stream them.
Using a Set for 2 million objects might not be the best idea, you may want to use a distinct or group by on the database instead.
Depending on what you are doing with the objects, you may also consider using a JPQL Update query instead.