title: Editing a row using Struts 2 and Hibernate is not working
body: <p>I am not able to edit table using struts2 hibernate. In Apache console I can see that the update query is executed but from table its just deleting the data and while trying to insert it getting inserted in a new row not in the same row. Can anyone please help what is wrong in this code</p>
  
  <p>DAO for edit:</p>
  
  <pre><code>public static boolean update(trainee p)
  {
      Boolean a=false;
      Session session=new Configuration().configure("hibernate.cfg.xml").buildSessionFactory().openSession(); 
       Transaction tp=session.beginTransaction();  
       trainee u=(trainee) session.get(trainee.class, p.getId());
       if(u!=null)
       {
       u.setAddress(p.getAddress());
       u.setPhone(p.getPhone());
       u.setAge(p.getAge());
       u.setTname(p.getTname());
       u.setGender(p.getGender());
       u.setTechnology(p.getTechnology());
       u.setEmail(p.getEmail());
       session.update(u);
       }
       tp.commit();
       System.out.println("Command successfully executed....");
       session.close();
       if(tp != null){
          a=true;
      }
             return a;
  }    
  </code></pre>
  
  <p>Action class:</p>
  
  <pre><code>public String update()
  {
      String x="input";
      trainee u=new trainee();
      u.setId(id);
      u.setAddress(address);
      u.setPhone(phone);
      u.setAge(age);
      u.setTname(tname);
      u.setGender(gender);
      u.setTechnology(technology);
      u.setEmail(email);
      if(RegisterDao.update(u))
          {
          x="success";
          }
      return x;
  }
  </code></pre>
  
  <p>Struts.xml</p>
  
  <pre><code>&lt;action name="update" class="com.ilp.action.taineeAction" method="update"&gt;
              &lt;result name="success" type="redirect"&gt;TraineeRegistration.jsp&lt;/result&gt;
              &lt;result name="input"&gt;ViewTrainees.jsp&lt;/result&gt; 
  &lt;/action&gt;
  </code></pre>
  
  <p>TraineeRegistration.jsp</p>
  
  <pre><code>&lt;s:form action="traineeReg"&gt;
  &lt;s:textfield label="TraineeName" name="tname"&gt;&lt;/s:textfield&gt;
  &lt;s:textfield label="Email Id" name="email"&gt;&lt;/s:textfield&gt;
  &lt;s:radio name="gender" list="{'Male','Female'}"&gt;&lt;/s:radio&gt;
  &lt;s:textfield label="Age" name="age"&gt;&lt;/s:textfield&gt;
  &lt;s:textfield label="Phone Number" name="phone"&gt;&lt;/s:textfield&gt;
  &lt;s:textarea label="Address" name="address"&gt;&lt;/s:textarea&gt;
  &lt;s:select name="technology" list="{'Java','J2ee','Dot Net','Oracle'}" headerKey="" headerValue="Select" label="SelectTechnology" /&gt;
  &lt;s:submit/&gt;
  &lt;/s:form&gt;
  </code></pre>
  
  <p>Hibernate.cfg.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!DOCTYPE hibernate-configuration PUBLIC  
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"  
        "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"&gt;  
  &lt;hibernate-configuration&gt;  
  
  &lt;session-factory&gt;  
      &lt;property name="hbm2ddl.auto"&gt;update&lt;/property&gt;  
      &lt;property name="hibernate.dialect"&gt;org.hibernate.dialect.MySQLDialect&lt;/property&gt; 
      &lt;property name="hibernate.connection.url"&gt;jdbc:mysql://localhost/javadb&lt;/property&gt;
      &lt;property name="connection.username"&gt;root&lt;/property&gt;  
      &lt;property name="connection.password"&gt;cis@123&lt;/property&gt;  
      &lt;property name="hibernate.connection.driver_class"&gt;com.mysql.jdbc.Driver&lt;/property&gt;  
      &lt;property name="show_sql"&gt;true&lt;/property&gt;
  &lt;mapping class="com.ilp.bean.trainee"/&gt;  
  &lt;/session-factory&gt;  
  </code></pre>
  
  <p> </p>
  
  <p>viewtrainee.jsp</p>
  
  <pre><code>&lt;%@ page language="java" contentType="text/html; charset=ISO-8859-1"
      pageEncoding="ISO-8859-1"%&gt;
      &lt;%@ taglib uri="/struts-tags" prefix="s" %&gt; 
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"&gt;
  &lt;title&gt;List Of Trainees Registered&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;table border=1px&gt;
  &lt;tr&gt;
  &lt;th&gt;Trainee Name&lt;/th&gt;
  &lt;th&gt;Email&lt;/th&gt;
  &lt;th&gt;Gender&lt;/th&gt;
  &lt;th&gt;Age&lt;/th&gt;
  &lt;th&gt;Ph No&lt;/th&gt;
  &lt;th&gt;Address&lt;/th&gt;
  &lt;th&gt;Technology&lt;/th&gt;
  &lt;th&gt;Edit&lt;/th&gt;
  &lt;th&gt;Delete&lt;/th&gt;
  &lt;s:iterator value="contactList"&gt;
      &lt;tr&gt;
          &lt;td&gt;&lt;s:property value="tname" /&gt;&lt;/td&gt;
          &lt;td&gt;&lt;s:property value="email" /&gt;&lt;/td&gt;
          &lt;td&gt;&lt;s:property value="gender" /&gt;&lt;/td&gt;
          &lt;td&gt;&lt;s:property value="age" /&gt;&lt;/td&gt;
          &lt;td&gt;&lt;s:property value="phone" /&gt;&lt;/td&gt;
          &lt;td&gt;&lt;s:property value="address" /&gt;&lt;/td&gt;
          &lt;td&gt;&lt;s:property value="technology" /&gt;&lt;/td&gt;
          &lt;td&gt;&lt;a href="update?id=&lt;s:property value="id"/&gt;"&gt;edit&lt;/a&gt;&lt;/td&gt;
          &lt;td&gt;&lt;a href="delete?id=&lt;s:property value="id"/&gt;"&gt;delete&lt;/a&gt;&lt;/td&gt;
      &lt;/tr&gt;
  &lt;/s:iterator&gt;
  &lt;/table&gt;
  
  &lt;a href="TraineeRegistration.jsp"&gt;Add Trainee&lt;/a&gt; &amp;nbsp;&amp;nbsp;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>