title: Could not synchronize database state with session
body: <p>Could not synchronize database state with session
  org.hibernate.exception.GenericJDBCException: could not update</p>
  
  <p>I am getting this error while I try to update my database. There is no unique key defined in my database, but id field has been defined as Primary Key. </p>
  
  <p>Here is the code of the update function :</p>
  
  <pre><code>public String updateAction(){
         Session session = null;
         try{
              SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
              session =sessionFactory.openSession();
              org.hibernate.Transaction tx = session.beginTransaction();
              Medicine medicine = (Medicine) session.load(Medicine.class, id);
              medicine.setBrandName(brandName);
              session.update(medicine);
              tx.commit();
         }
         catch(Exception ex){
              ex.printStackTrace();
         }
         finally{
              session.close();
         }
         return "index";
      }
  </code></pre>
  
  <p>hibernate.config.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="hibernate.dialect"&gt;org.hibernate.dialect.MySQLDialect&lt;/property&gt;
      &lt;property name="hibernate.connection.driver_class"&gt;com.mysql.jdbc.Driver&lt;/property&gt;
      &lt;property name="hibernate.connection.url"&gt;jdbc:mysql://localhost:3306/medicine&lt;/property&gt;
      &lt;property name="hibernate.connection.username"&gt;root&lt;/property&gt;
      &lt;property name="hibernate.connection.password"&gt;root&lt;/property&gt;
      &lt;property name="hibernate.show_sql"&gt;true&lt;/property&gt;
      &lt;property name="hibernate.current_session_context_class"&gt;thread&lt;/property&gt;
      &lt;property name="hibernate.query.factory_class"&gt;org.hibernate.hql.classic.ClassicQueryTranslatorFactory&lt;/property&gt;
      &lt;property name="hibernate.jdbc.factory_class"&gt;org.hibernate.jdbc.NonBatchingBatcherFactory&lt;/property&gt;
      &lt;mapping resource="mediview/Medicine.hbm.xml"/&gt;
    &lt;/session-factory&gt;
  
  &lt;/hibernate-configuration&gt;
  </code></pre>
  
  <p>Medicine.java:</p>
  
  <pre><code>    public class Medicine  implements java.io.Serializable {
  
           private String id;
           private String brandName;
  
           public Medicine() {
           }
  
       public Medicine(String id) {
            this.id = id;
       }
  
       public Medicine(String id, String brandName) {
            this.id = id;
            this.brandName = brandName;
       }
  
       public String getId() {
            return this.id;
       }
  
       public void setId(String id) {
            this.id = id;
       }
  
       public String getBrandName() {
            return this.brandName;
       }
  
      public void setBrandName(String brandName) {
          this.brandName = brandName;
      }
  }
  </code></pre>
  
  <p>Medicine.hbm.xml:</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
  "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"&gt;
  &lt;!-- Generated 14 Aug, 2013 8:46:46 PM by Hibernate Tools 3.2.1.GA --&gt;
  &lt;hibernate-mapping&gt;
      &lt;class name="mediview.Medicine" table="medicine" catalog="medicine"&gt;
          &lt;id name="id" type="string"&gt;
              &lt;column name="ID" length="5" /&gt;
              &lt;generator class="assigned" /&gt;
          &lt;/id&gt;
          &lt;property name="brandName" type="string"&gt;
              &lt;column name="BrandName" length="30" /&gt;
          &lt;/property&gt;
      &lt;/class&gt;
  &lt;/hibernate-mapping&gt;
  </code></pre>