-->
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.  [ 2 posts ] 
Author Message
 Post subject: need Guide for understanding the Hibernate...
PostPosted: Tue Jun 10, 2008 11:24 pm 
Beginner
Beginner

Joined: Sat May 31, 2008 2:35 am
Posts: 30
Location: pakistan
i m new in hibernate and study that framwork...

can any one from there guide me ....


1: when i was storing the obj from application to DB...
i use:

SessionFactory sessionFactory = new
Configuration().configure().buildSessionFactory();
session =sessionFactory.openSession();


2: when i want to read the Table data i use DAO object to treverse it and show me the value by using List.....
i use:

ProductDAO ob=new ProductDAO();
List<Product> li=ob.findAll();


----------------------------------
can Someone Guide me In which Senario these two object i use...
i mean when i use Session and when DAO...


and plzz Refer me the free E-book which build my Concept

that is most basic and time consuming post but hope Guide me
Thanx in advance


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 11, 2008 9:47 am 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
Well, there may be a hundred different answers to your question, depending on how the DAO is implemented.

Here's a quick take.

A DAO simplified accessing data from a database. As such, it needs to interact with the database, which means it needs a TRANSACTION. So, a DAO needs a transaction in order to do its work.

Opening a Hibernate Session can be thought of as connecting to your database, and before you do anything with that connection, you need to ask the Hibernate Session to start a transaction. So, to connect to the database and start a transaction, you need the Hibernate Session. Starting to see how the DAO and the Hibernate Session might work hand in hand?

Now, if your DAO gets a list from the database, when should the transaction be started, and the connection to the database opened? Before the list method on the DAO is invoked, or after, aka, inside the list method?

Well, in the world of client demarcation, you'd do it before the list method is called. For various reasons, sometimes it must be done in other places, maybe even inside the DAO (although that tends to fall into the one-transaction-per-method anti-pattern.)

So, that's a quick answer. We can get much more complicated, and take the discussion in many different directions, but I think that's a pretty quick intro.

For some more information on Hibernate and some tutorials, check out some of the examples on my website:

http://jpa.ezhibernate.com/Javacode/learn.jsp?tutorial=23whatishibernate

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