[an error occurred while processing this directive]

Hibernate Update Query


In this tutorial we will show how to update a row with new information by retrieving data from the underlying database using the hibernate. Lets first write a java class to update a row to the database.

Create a java class:
Here is the code of our java file (UpdateExample.java), where we will update a field name "InsuranceName" with a value="Jivan Dhara" from a row of the insurance table.

Here is the code of delete query: UpdateExample .java 

package roseindia.tutorial.hibernate;

import java.util.Date;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;

public class UpdateExample {
   @param args
  public static void main(String[] args) {
    // TODO Auto-generated method stub
    Session sess = null;
    try {
      SessionFactory fact = new Configuration()
      sess = fact.openSession();
      Transaction tr = sess.beginTransaction();
      Insurance ins = (Insurance)sess.get
Insurance.class, new Long(1));
      ins.setInsuranceName("Jivan Dhara");
      ins.setInvestementDate(new Date());
      System.out.println("Update successfully!");
    catch(Exception e){

Download this code.


log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).

log4j:WARN Please initialize the log4j system properly.

Hibernate: select insurance0_.ID as ID0_0_, insurance0_.insurance_name as insurance2_0_0_, insurance0_.invested_amount as invested3_0_0_, insurance0_.investement_date as investem4_0_0_ from insurance insurance0_ where insurance0_.ID=?

Hibernate: update insurance set insurance_name=?, invested_amount=?, investement_date=? where ID=?

Update successfully!


[an error occurred while processing this directive]