-->
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: Basic question about list queries and transactions
PostPosted: Mon Jan 11, 2010 7:13 pm 
Newbie

Joined: Wed Jan 06, 2010 9:09 pm
Posts: 14
Hi All,

I'm going through the initial tutorial, why is it that the listEvents function below needs to wrap the list function in a transaction? I would've thought we could do a read only query without needing a transaction?

From tutorial:

private List listEvents() {
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
List result = session.createQuery("from Event").list();
session.getTransaction().commit();
return result;
}


Top
 Profile  
 
 Post subject: Re: Basic question about list queries and transactions
PostPosted: Sun Jan 17, 2010 11:47 pm 
Newbie

Joined: Wed Dec 23, 2009 12:38 pm
Posts: 14
For every interaction thru Hibernate layer, you need to have a Transaction [ This is hibernate transaction object and not the JDBC Transaction one]. This object internally manages the resources and acts specific to the underlying JDBC connection.

Hence you need to begin transaction for INSERT, UPDATE, READ , DELETE in Hibernate.


Top
 Profile  
 
 Post subject: Re: Basic question about list queries and transactions
PostPosted: Mon Jan 18, 2010 9:34 am 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
Essentially, this code is going to the database, and to go to the database, you need a transaction. A transaction simply represents a 'unit of work' at the most basic level. Going to the database is work. :)

_________________
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  
 
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.