-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: Hibernate in web applications
PostPosted: Mon Feb 23, 2004 8:32 am 
Beginner
Beginner

Joined: Mon Nov 24, 2003 11:47 am
Posts: 22
Hi, I have large Hibernate application (about 40 Hibernate mapping classes). I use ThreadLocal pattern. For every http request I open session in my SessionThreadLocal and when page is completly done I closed session (in Filter).

But this is not all right, because new Hibernate Session object need more than 1 second for first .load(). What is proper patter for web applications ? Do not close session in SessionThreadLocal (only call session.clear()) ?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 23, 2004 8:51 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
This is the correct pattern, I'd also consider your application quite small. The performance problems you see have nothing to do with your usage of the Session ThreadLocal (at least I hope so), but we can't help you, as you have not shown any code.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 23, 2004 10:30 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
I hope you don't build the SessionFactory every time, too?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 23, 2004 11:31 am 
Beginner
Beginner

Joined: Mon Nov 24, 2003 11:47 am
Posts: 22
Example test:
Code:
      public void testManySessions() throws Exception {
      long t;
      SessionFactory fac = HibernateProvider.getSessionFactory();
      for (int i = 0; i < 10; i++) {
         t = System.currentTimeMillis();
         Session session = fac.openSession();
         Kurz kurz = (Kurz) session.load(Kurz.class, new Long(1));
         session.close();
         log.debug("time: " + (System.currentTimeMillis() - t) + "ms");
      }
     }


Result:
Code:
16:22:23,687 DEBUG HibernateSimpleTest:134 - time: 2859ms
16:22:26,515 DEBUG HibernateSimpleTest:134 - time: 2828ms
16:22:29,421 DEBUG HibernateSimpleTest:134 - time: 2906ms
16:22:32,234 DEBUG HibernateSimpleTest:134 - time: 2813ms
16:22:35,093 DEBUG HibernateSimpleTest:134 - time: 2859ms
16:22:37,906 DEBUG HibernateSimpleTest:134 - time: 2797ms
16:22:40,734 DEBUG HibernateSimpleTest:134 - time: 2828ms
16:22:41,921  WARN SessionImpl:3358 - unclosed connection
16:22:41,968  WARN SessionImpl:3358 - unclosed connection
16:22:43,843 DEBUG HibernateSimpleTest:134 - time: 3109ms
16:22:46,656 DEBUG HibernateSimpleTest:134 - time: 2813ms
16:22:49,421 DEBUG HibernateSimpleTest:134 - time: 2765ms


Is this normal behaviour ?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 23, 2004 11:35 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
I don't consider this normal, enable logging and check whats going on there. I suspect you have a lot of non-lazy collections and you are acutally loading the complete object graph there.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.