We are worried about similar issues with the following setup:
- Hibernate 3.3.1
- 5 persistence-units
- 286 entities (amongst 3 applications: 230, 22, 34 entities per application respectively)
That makes a total of about 1400 mapped entities, each entity being mapped in each persistence-unit.
The profiler shows that Hibernate classes take about 250 MB (a similar memory usage to the one of Hernán's setup), but with almost 2 times more entities. But still, 250 MB is about 20% of the application server total memory usage: quite a lot only for mappings. So we are also interested by reducing the Hibernate mapping memory usage (and having dynamic datasource selection on a single SessionFactoryImpl as suggested by
Jeff Nadeau is not applicable: we need the cache).
Most of the memory usage is in the SessionFactoryImpl (about 20 MB per instance). The average SessionFactoryImpl contains:
- QueryCachePlan : about 0-8 MB (varies)
- EventListeners: about 6 MB (stable)
- other smaller objects
99% of the EventListeners memory usage is held by org.hibernate.validator.event.ValidateEventListener, which itself holds a EJB3ReflectionManager which holds about 4.8 MB.
So we turned Hibernate validation off by using
Pascal Thivent's tips in the persistence.xml file :
Code:
<property name="hibernate.validator.apply_to_ddl" value="false"/>
<property name="hibernate.validator.autoregister_listeners" value="false"/>
This reduced Hibernate mappings memory usage by about 30%. Of course, we have no more Hibernate validation on inserts and updates: that's the price to pay...
We didn't check if the memory increases in 3.6.x and in 4.x as reported by Hernán, but disabling Hibernate validation could probably be used.
Hernán: do you have the details about the top memory usage classes ?
Kindly regards,
Julien