Get all updates of Java4s
Follow Us: Email Newsletter

Hibernate In Servlet Example, Hibernate In Servlet Tutorial

Hibernate » On Jul 20, 2011 { 4 Comments } By Sivateja

With servlet, if we want to do some operations on the database, then we can also use hibernate ORM rather than JDBC.  We call this as servlet-Hibernate integration.

While integration servelt with hibernate, it is there to follow these setps

  • In init() method of servlet, we need to create SessionFactory of hibernate, because SessionFactory is an heavy weight component, its the programmer responsibulity to make it as singleton, for this we need to create the object of SessionFactory in init() method of servelet
  • Open a Session in service() method and perform the operations on the database close the Session in service()
  • Close the SessionFactory of hibernate in destroy() method
  • While integration servlet with hibernate, hibernate mapping files (.hbm.xml) and hibernate configure files(cfg.xml) need to be stored in classes folder only
  • In the lib folder, we need to store all the jars related to hibernate and database

Let us see an example on this servelt with  hibernate in the next session

You Might Also Like

  ♦ About Author ♦

Java4s_Author
sivateja@java4s.com
Full Stack( Java/J2EE & UI/UX ) Developer and founder of Java4s - Get It Yourself, A popular Java/J2EE Programming Blog. Sign-up for the Email Newsletter for your daily dose of Java tutorials.

Comments

4 Responses to “Hibernate In Servlet Example, Hibernate In Servlet Tutorial”
  1. Praveen says:

    Thanks allotted…

  2. Mahi says:

    Thanks alot

    But in your site there is some spelling mistakes is there correct them for site development.

    I thought my comment is help full for you if not ignore it.
    Thank you!

Name*
Mail*
Website



By posting your answer, you agree to our comments policy.
What would you like to learn today?
Browse these popular technologies
Hibernate spring struts Servlets ajax Log4j jQuery Json Core Java Web Services AngularJs
Most Recent Tutorials
Hibernate_Logo Hibernate Recent Posts Spring_Logo Spring Recent Posts Struts_Logo Struts Recent Posts
Useful Links Current & UpComing Tutorials
Upcoming
  Web Services [ SOAP ], JSP
Contact | About Us | Privacy Policy | Advertise With Us

© 2010 - 2016 Java4s - Get It Yourself.
The content is copyrighted to Sivateja Kandula and may not be reproduced on other websites.