I am struggling with this. I have MVC based web app. I open up some session in the BO object and pass it to DAO. But most of the time is consumed in the opensession() call. I would want to reduce that.
This is how my util method looks like from where I get the sessions.
yea, so I have a restful api. For every request I call openssesion and close it on completing the request. Whenever there is an on opensession call, it reads all the hbm.xml files etc.
which to me seems a bit slow. Instead the app should read the xml mapping only once, when the app starts..
Whenever there is an on opensession call, it reads all the hbm.xml files etc.
sessionFactory is static and it should be initialized when the class if initialized i.e. only once, after that each call to openSession won't initialize the SessionFactory thus your hibernate configuration files should be read only once. Are you sure call to openSession method is taking up too much time and not other logic in your code??