I have an application with about 3000 entity classes.
Due to the large number of classes the SessionFactory object consumes about 150 MB of memory and takes almost a minute to setup (process all classes, generate the proxies and building the meta model).
After profiling the process I've discovered that a minute of the time is spent in org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory while half is in org.hibernate.tuple.entity.AbstractEntityTuplizer.<init>(EntityMetamodel, PersistentClass).
I'm looking for ways to reduce the SessionFactory memory usage and load time.
One thought was to move the class enhancement to compile time, but I didn't find much information about it.
The number of entities is a fact that I can't change but if someone has better ideas on how to handle their database access (other than Hibernate) I'll be happy to hear about it.
3000 classes just sound too crazy for me.
what do you mean by "class enhancement"?
I think you should carefully reconsider the design of your application.
Hibernate heavily uses Proxy objects (for example, when you run a setter, the Proxy "aggregates" this change, so Hibernate can generate an update SQL with only changed fields).
Hibernate also uses class information in memory used by the proxies (as explained above) and this is why your memory grows like this
Start by looking at what's happening inside the SessionFactory. Hibernate offers a JMX connector, see documentation here. Then you can start to look into your hotspots and how to refactor them. You really need to begin with gathering some more metrics. Right now it could be anything, including GC problems.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With