Can any one please suggest me the best way of retrieving the records in hibernate [closed]
Can any one please suggest me the best way of retrieving the records in hibernate [closed]
I am working on a batch application where I have to retreive millions of records and need toprocess it individually. We are using hibernate to connect to DB.
I have tried using HQL and Criteria API to fetch the records(using the query Select * from table_name).
But it is taking more than 5 min .Sometimes it is getting hanged.
Can anyone suggest me the best approach for the data retrieving.
Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
1 Answer
1
You may want to employ cursors, and if your queries are as simple as you indicated, pure JDBC may be sufficient - like here: https://docs.oracle.com/javase/tutorial/jdbc/basics/retrieving.html
Also, consider adding the WHERE
clause to eliminate rows that can be recognized as irrelevant for your purposes.
WHERE
And depending on your table and queries, adding an index may also help.
If you need to use hibernate, you can use ScrollableResults
as mentioned here: https://stackoverflow.com/a/9891008/455449
ScrollableResults
Actually, I am using hibernate in our project for ORM purpose.But , in the scenario that I have mentioned , taking more time to fetch.Can I implement similar way in hibernate.
– Pesala Sairam
Sep 10 '18 at 18:40
for that case, I found a related answer and mentioned in my text, but I never tried this myself
– Petr Kozelka
Sep 10 '18 at 18:46
In this case, I believe your question was closed as too broad, not because you wanted to both process and retrieve the records, but because there could be countless possible causes of this problem, and without code and an attempt to troubleshoot the problem, there's no way to figure out what the specific problem you're trying to solve is.
– divibisan
Sep 10 '18 at 20:10