File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes hibernate opensession Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "hibernate opensession" Watch "hibernate opensession" New topic
Author

hibernate opensession

Mag Wells
Ranch Hand

Joined: Jun 02, 2010
Posts: 38
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

Joined: Apr 14, 2004
Posts: 10336

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?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Mag Wells
Ranch Hand

Joined: Jun 02, 2010
Posts: 38
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

Joined: Aug 03, 2008
Posts: 9293
    
  17

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


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: hibernate opensession