Reputation: 2758
I am experiencing a memory leak in a Hibernate session.
A long running thread is continuously loading and updating data. While the thread regularily calls entityManager.clear()
I observe both:
1.) growth in Session
-size (linear growth since start of application)
2.) growth in execution-time (exponential growth since start of application)
The only thing, that seems to help is to close()
the entitymanager and re-open it. I have seen this behaviour in several unconnected applications, some with spring, some without, some using the jpa-frontend, some using hibernate natively.
Weird enough: while I have never encountered a hibernate application without this problem, searching the internet comes up blank. What am I (and dozens of other developers) doing wrong?
Upvotes: 4
Views: 6122
Reputation: 2145
There is a bug in hibernate that prevent clear for clearing session cleanly. See:
It should be fixed in 4.3.
My workaround is to use short-lived session.
Upvotes: 3