After initializing a Hibernate SessionFactory with over 800 mapping files, I profile my application and see that the SessionFactoryImpl is holding onto 475MB memory (mostly in the form of Strings and char). Is there any way to reduce this? In particular, is there a way for some of this memory be allocated when that particular entity/mapping is accessed so that an application which only access a subset of the entity types won't load all of the mappings?
This problem was bad in hibernate 3.3.1 (225MB) but has gotten ridiculous in hibernate3.5 (475MB).
Yes it is causing quite a large problem. Some users of the application are only using a very small set of the functionality and yet they need to allocate 595MB just for the hibernate SessionFactoryImpl memory footprint. At this point their machines don't have enough memory to run the application.
Well 800 mapped entities is quite a lot, so Hibernate is going to do a fair bit when it configures the SessionFactory. The only solution I can think of (if increasing the heap is not possible) is to break your application out in to multiple SessionFactories, assuming your application can support this sort of compartmentalization? Quite a heavy duty and intrusive fix though. It might be more prudent to just get those purchase orders in for more RAM.