Latest Tutorials| Questions and Answers|Ask Questions?|Site Map

Home Hibernate Hibernate save()


Share on Google+Share on Google+

Hibernate save()

This tutorial explain how save() works in hibernate.

Hibernate save()

This tutorial explain how save() works in hibernate.

Hibernate save() :

The function of save() is to save content into database. It saves new record without caring of existence of ID. object) : saves the instance of persistent class into database table.
Here object is your persistent class. entityName, Object object) : Persist the given transient instance, first assigning a generated identifier.
Here is two parameter one is entityName and other is Object, your persistent class.

Example :  In this example we are saving student record by using save().

package net.roseindia.main;

import net.roseindia.table.Student;
import net.roseindia.util.HibernateUtil;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;

public class MainClazz {

public static void main(String[] args) {
Session session = HibernateUtil.getSessionFactory().openSession();
Transaction transaction = null;
try {transaction=session.beginTransaction();
Student student=new Student();
System.out.println("Record saved");
} catch (HibernateException e) {
} finally {


Hibernate: insert into student (course, name) values (?, ?)
Record saved

Click here to download complete code


If you enjoyed this post then why not add us on Google+? Add us to your Circles

Liked it!  Share this Tutorial

Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: July 21, 2012

Related Tutorials

Discuss: Hibernate save()  

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image