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.
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.