Newsletter

Hibernate In Servlet Example, Hibernate In Servlet Tutorial

Hibernate » on Jul 20, 2011 { 5 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 the Author .::

Java4s_Author
Sivateja Kandula - Java/J2EE Full Stack Developer
Founder of Java4s - Get It Yourself, A popular Java/J2EE Programming Blog, Love Java and UI frameworks.
You can sign-up for the Email Newsletter for your daily dose of Java tutorials.

Comments

5 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!

  3. Soumya Ranjan says:

    I want to do CRUD operation using html, servlet,Hibernate.Give me a example how to integrate servlet and hibernate.

Name*
Mail*
Website



By posting your answer, you agree to our comments policy.
Most Recent Posts from Top Categories
Spring Boot Hibernate Spring
Contact | About Us | Privacy Policy | Advertise With Us

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