Hi, welcome.
some hints:
1) Which database is it? MySQL's driver ignores the request for scrollableresults, it basically fetches the whole data in a single query. Yes that's extremely stupid, as it might not fit in memory, but you can experiment with some driver parameters to "fix" that.
2) In the catch block instead of ignoring the error you should make sure you close the Session and replace it with a new one: Hibernate's Sessions should be discarded after an error.
3) Can you try scrolling on the data but commenting out the
Code:
fullTextSession.index(metadataList.get(0));
So we can undersand if you're going in OOM because of the indexing or because of the data loading from the database
4) I'd strongly advise to fix the data on the database, so you can use the MassIndexer. You should be able to do that easily with some SQL statements? like to remove all references to invalid foreign keys.
5) Use the formatting options of the forum, so we can read your code better ;)