SessionFactory implements Serializable, so you should be able to save it - I was contemplating doing just that, but did not try it yet.
What discouraged me was the fact that I would have to watch not only for changes in all my mapping files, BUT also for any object implementation file changes - SessionFactory uses CGLIB to generate code from your persistent classes.
Hence, optimizing the load by serialization would not help me much during development, and in production, the startup time is less of an issue.
Your other options are:
- Use multiple session factories - each covering a different portion of your schema - if possible (granted, more things to worry about)
- Perform SessionFactory initialization in a background thread, so that (while SessionFactory intializes), you can build your UI and other 'stuff'.
For example, we have a separate SessionFactory (well, and sometimes database) for authentication - so while the user is coping with the login, we can happily initialize our BIG SessionFactory (using a lower-priority thread).
Don't forget to rate this posting!
|