-->
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.  [ 3 posts ] 
Author Message
 Post subject: opening Session
PostPosted: Thu May 29, 2008 4:57 am 
Newbie

Joined: Thu May 29, 2008 4:41 am
Posts: 4
3.2.2:

Hi, I'm new on hibernate.
I've to store in some db tables with data that must frequently updated.

At the moment I open a new session every time I've to store something, but I think that maybe there exists better solutions (I've read also about hibernate cache, but I haven't understood exactly how it works).

any suggestions?
thanks in advance


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 29, 2008 9:50 am 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
With the Hibernate cache, basically, when you open a session, and start a transaction, the Hibernate Session keeps a local copy of the Java object (the entity), and makes changes to that local copy. Since this all happens within a transaction, and the database is locked (?), then just manipulating the local object makes more sense than going back and forth to the database. However, once the HibernateSession's transaction is committed, the final state of the POJO is persisted to the database.

In web applications, a simple way to keep a session open is to use a ServletFilter and open a Hibernate Session and start a transaction before the filter chain, and then commit the transaction after the filter chain has completed. With that, the session lasts the duration of the request, and you avoid LazyInitializationExceptions in your JSP pages and Servlets. Google for Open Session in View pattern for more details.

For more information on opening and closing sessions, take a look at the following tutorial on How Hibernate Works:

http://www.thebookonhibernate.com/Hiber ... rnateworks

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 29, 2008 10:43 am 
Newbie

Joined: Thu May 29, 2008 4:41 am
Posts: 4
Thanks Cameron,

Anyway in my application webAppl has only a monitoring function of another appl that receive data and save them on db.

thanks


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.