Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate session

 
tarik el berrak
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all,

I want to know exactly what is an hibernate session ???

Thanks
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Hibernate documentation best covers this. At its most basic you could consider the Session a simple in-memory cache of database objects.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We have a separate forum for O/R questions. I'll move this to it for you.
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Hibernate Session is the workhorse that makes your Hibernate applications work.

Once a JPA annotated JavaBean touches the Session, the Session will manage its state. You can then update a JavaBean, change its values, and do all sorts of neat stuff, and if the Session is involved, it will persist all of those changes to the underlying database.


With a magical and mystical object known as the Hibernate Session, persisting the state of your Java objects is easy. Look how readable and understandable the following code is:

User user = new User(); //an object named user is created
user.setName("Cameron"); //name is initialized to Cameron
user.setPassword("n0tte11ing");//password is initialized to n0tte11ing
Session hibernateSession = HibernateUtil.getSession();
//get the magical Hibernate session
hibernateSession.save(user); //save the user to the database!

The line of code hibernateSession.save(user); saves the state of the user instance to the database. Of course, there's a little bit of plumbing code that needs to go in there to make the whole hibernate framework work; But setting up that plumbing code really isn't that bad. Overall, Hibernate is real easy to use, fairly easy to set up, and probably the easiest way to manage the persistent state of you domain model objects.


The Hibernate Session is really neat.

Here's a little tutorial on "What is Hibernate". Check it out.

What is Hibernate? What is Java Persistence? What is JPA?

A more advanced read is the link on How Hibernate Works.
[ April 28, 2008: Message edited by: Cameron Wallace McKenzie ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic