If you get memory issues and the SessionFactory
seems to be the culprit, then it can be due to the following reasons:
- Either you have enabled the 2nd-level cache and cached all entities and configured Ehcache to store all entities in-memory. Try to limit the memory size occupied by your cached entries to something more reasonable.
- The underlying
Session
objects are too large because you are fetching millions or records with your queries. Make sure you use pagination in your queries. - You have configured the JVM to use a tiny amount of maximum allocated memory and you should raise the
Xmx
JVM flag.