• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

hibernate opensession

 
Mag Wells
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Any better suggestion ?
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Opening and closing sessions are light weight operations. Configuring your SessionFactory is heavy weigh, so I'd expect the first call to this to be slow. Are subsequent calls sloww as well?
 
Mag Wells
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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..

how do I do that ?
 
Ankit Garg
Sheriff
Posts: 9528
32
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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??
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic