title: Error with updating table using java hibernate as "could not execute statement" error
body: <p>Using Java and hibernate, I was to change the Database definition after creation, just by making changes to my existing Entity Class. Will the Changes be reflected in the Database??? Is it Possible??? I tried and Failed. I have tried <code>&lt;property name="hibernate.hbm2ddl.auto"&gt;update&lt;/property&gt;</code> But getting error, Can anyone guide me with the proper method, here is my code.</p>
  
  <pre><code>/**
   * Description of bankbranchcontactdetailsBean
   *
   * @author Vishal Jain @ TurtleTec Inc.
   */
  package com.beans;
  
  import javax.persistence.Entity;
  import javax.persistence.Table;
  import javax.persistence.TableGenerator;
  import javax.persistence.Id;
  import javax.persistence.Column;
  import javax.persistence.Temporal;
  import javax.persistence.UniqueConstraint;
  import javax.persistence.GeneratedValue;
  import javax.persistence.GenerationType;
  import java.io.Serializable;
  import java.util.Date;
  
  @Entity(name = "bankbranchcontactdetails")
  @Table(name = "bankbranchcontactdetails", schema = "stserptest", uniqueConstraints = { @UniqueConstraint(columnNames = "BankBranchContactId") })
  @TableGenerator(name = "bankbranchcontactdetailsgen", table = "bankbranchcontactdetails", pkColumnName = "BankBranchContactId")
  public class bankbranchcontactdetailsBean extends SuperBeanClass implements
          SuperBeanInterface, Serializable {
  
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      @Column(columnDefinition = "INT(10) UNSIGNED", name = "BankBranchContactId", precision = 10, scale = 0, nullable = false, unique = true)
      private Integer Id;
  
      @Column(columnDefinition = "INT(10) UNSIGNED", name = "BankBranchId", precision = 10, scale = 0, nullable = false)
      private Integer _BankBranchId;
  
      @Column(columnDefinition = "ENUM('PHONE','MOBILE','FAX','TELEX')", name = "ContactTypeModified", length = 6, nullable = false)
      private String _ContactTypeModified;
  
      @Column(columnDefinition = "VARCHAR(20)", name = "Contact", length = 20, nullable = false)
      private String _Contact;
  
      @Column(columnDefinition = "INT(10) UNSIGNED", name = "NewField", precision = 10, scale = 0, nullable = true)
      private Integer _NewField;
  
      public bankbranchcontactdetailsBean() {
  
          _BankBranchId = 0;
          _ContactType = "";
          _Contact = "";
          _NewField = 0;
      }
  
      public bankbranchcontactdetailsBean(Integer __BankBranchId,
              String __ContactTypeModified String __Contact, Integer __MyCompanyId) {
  
          _BankBranchId = __BankBranchId;
          _ContactTypeModified = __ContactTypeModified;
          _Contact = __Contact;
          _MyCompanyId = __MyCompanyId;
      }
  
      public int getBankBranchContactId() {
          return Id;
      }
  
      public Integer getBankBranchId() {
          return _BankBranchId;
      }
  
      public String getContactType() {
          return _ContactTypeModified;
      }
  
      public String getContact() {
          return _Contact;
      }
  
      public Integer getNewField() {
          return _NewField;
      }
  
      public void setBankBranchContactId(int NewValue) {
          Id = NewValue;
      }
  
      public void setBankBranchId(Integer NewValue) {
          _BankBranchId = NewValue;
      }
  
      public void setContactType(String NewValue) {
          _ContactTypeModified = NewValue;
      }
  
      public void setContact(String NewValue) {
          _Contact = NewValue;
      }
  
      public void setNewField(Integer NewValue) {
          _NewField = NewValue;
      }
  
  }
  
  
  
  
  &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/mysql?zeroDateTimeBehavior=convertToNull&lt;/property&gt;
          &lt;property name="hibernate.connection.username"&gt;root&lt;/property&gt;
          &lt;property name="hibernate.connection.password"&gt;V32&lt;/property&gt;
          &lt;property name="hibernate.default_schema"&gt;stserptest&lt;/property&gt;
          &lt;property name="hibernate.hbm2ddl.auto"&gt;update&lt;/property&gt;
              &lt;property name="hibernate.archive.autodetection"&gt;class&lt;/property&gt;
              &lt;property name="hibernate.show_sql"&gt;true&lt;/property&gt;
              &lt;property name="hibernate.format_sql"&gt;true&lt;/property&gt;
  
          &lt;mapping class="com.stserp.beans.bankbranchcontactdetailsBean" /&gt;
  
      &lt;/session-factory&gt;
  &lt;/hibernate-configuration&gt;
  
  
  
  /**
   * Description of ManagerClass
   *
   * @author Vishal Jain 
   */
  package com.beans;
  
  import java.util.ArrayList;
  
  import javax.swing.JOptionPane;
  
  import org.hibernate.HibernateException;
  import org.hibernate.Session;
  import org.hibernate.SessionFactory;
  import org.hibernate.cfg.Configuration;
  import org.hibernate.service.ServiceRegistry;
  import org.hibernate.service.ServiceRegistryBuilder;
  
  public class ManagerClass {
  
      private static SessionFactory factory = null;
      private static ManagerClass _ManagerClass = null;
  
      public static SessionFactory createSessionFactory() {
          SessionFactory sessionFactory;
          Configuration configuration = new Configuration();
          configuration.configure();
          ServiceRegistry serviceRegistry = new ServiceRegistryBuilder()
                  .applySettings(configuration.getProperties())
                  .buildServiceRegistry();
          sessionFactory = configuration.buildSessionFactory(serviceRegistry);
          return sessionFactory;
      }
  
      public static SessionFactory getSessionFactory() {
          return factory;
      }
  
      public static ManagerClass getInstance() throws ExceptionInInitializerError {
          try {
              if (factory == null) {
                  factory = createSessionFactory();
              }
              if (_ManagerClass == null) {
                  _ManagerClass = new ManagerClass();
              }
          } catch (Throwable ex) {
              JOptionPane.showMessageDialog(
                      null,
                      "Failed to create sessionFactory object...\n"
                              + ex.getMessage(), "Error...", 0);
              throw new ExceptionInInitializerError(ex);
          } finally {
              return _ManagerClass;
          }
      }
  
      public ArrayList&lt;Integer&gt; SaveBeansList(Session session, String entityName,
              ArrayList&lt;? extends SuperBeanClass&gt; BeansList)
              throws HibernateException {
          ArrayList&lt;Integer&gt; IDs = null;
          try {
              IDs = new ArrayList&lt;Integer&gt;();
              for (SuperBeanClass element : BeansList) {
                  IDs.add((Integer) session.save(entityName, element));
              }
          } catch (HibernateException e) {
              throw e;
          }
          return IDs;
      }
  
      public ArrayList&lt;? extends SuperBeanClass&gt; LoadTable(Session session,
              String TableName) throws HibernateException {
          ArrayList&lt;? extends SuperBeanClass&gt; beansList = null;
          try {
              beansList = (ArrayList&lt;? extends SuperBeanClass&gt;) session
                      .createQuery("FROM " + TableName).list();
          } catch (HibernateException e) {
              throw e;
          }
          return beansList;
      }
  
      public ArrayList&lt;?&gt; LoadConditional(Session session, String _query)
              throws HibernateException {
          ArrayList&lt;?&gt; beansList = null;
          try {
              beansList = (ArrayList&lt;? extends SuperBeanClass&gt;) session
                      .createQuery(_query).list();
          } catch (HibernateException e) {
              throw e;
          }
          return beansList;
      }
  
      public SuperBeanInterface LoadById(Session session, Class className,
              Integer ID) throws HibernateException {
          SuperBeanInterface BeanInterface = null;
          try {
              BeanInterface = (SuperBeanInterface) session.get(className, ID);
          } catch (HibernateException e) {
              throw e;
          }
          return BeanInterface;
      }
  
      public void DeleteById(Session session, Class className, Integer ID)
              throws HibernateException {
          try {
              session.delete(session.get(className, ID));
          } catch (HibernateException e) {
              throw e;
          }
      }
  }
  
  
  
  
  /**
   * Description of SuperBeanClass
   *
   * @author Vishal Jain 
   */
  package com.beans;
  
  public class SuperBeanClass {
      public SuperBeanClass() {
      }
  }
  
  
  
  /**
   * Description of SuperBeanInterface
   *
   * @author Vishal Jain 
   */
  package com.beans;
  
  public interface SuperBeanInterface {
  }
  </code></pre>
  
  <p>Here the field 'ContactType' has been Changed to 'ContactTypeModified' and a new Field 'NewField' has been added to the Entity Class <code>bankbranchcontactdetailsBean</code>. No manual changes have been made to the existing Database Table <code>bankbranchcontactdetails</code>. I am getting Error upon the execution of the program which is as Follows :</p>
  
  <pre><code>Aug 14, 2014 10:13:59 AM org.hibernate.annotations.common.Version &lt;clinit&gt;
  INFO: HCANN000001: Hibernate Commons Annotations {4.0.2.Final}
  Aug 14, 2014 10:13:59 AM org.hibernate.Version logVersion
  INFO: HHH000412: Hibernate Core {4.2.6.Final}
  Aug 14, 2014 10:13:59 AM org.hibernate.cfg.Environment &lt;clinit&gt;
  INFO: HHH000206: hibernate.properties not found
  Aug 14, 2014 10:13:59 AM org.hibernate.cfg.Environment buildBytecodeProvider
  INFO: HHH000021: Bytecode provider name : javassist
  Aug 14, 2014 10:13:59 AM org.hibernate.cfg.Configuration configure
  INFO: HHH000043: Configuring from resource: /hibernate.cfg.xml
  Aug 14, 2014 10:13:59 AM org.hibernate.cfg.Configuration getConfigurationInputStream
  INFO: HHH000040: Configuration resource: /hibernate.cfg.xml
  Aug 14, 2014 10:13:59 AM org.hibernate.internal.util.xml.DTDEntityResolver resolveEntity
  WARN: HHH000223: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!
  Aug 14, 2014 10:13:59 AM org.hibernate.cfg.Configuration doConfigure
  INFO: HHH000041: Configured SessionFactory: null
  Aug 14, 2014 10:13:59 AM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
  INFO: HHH000402: Using Hibernate built-in connection pool (not for production use!)
  Aug 14, 2014 10:13:59 AM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
  INFO: HHH000115: Hibernate connection pool size: 20
  Aug 14, 2014 10:13:59 AM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
  INFO: HHH000006: Autocommit mode: false
  Aug 14, 2014 10:13:59 AM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
  INFO: HHH000401: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql://localhost:3306/mysql?zeroDateTimeBehavior=convertToNull]
  Aug 14, 2014 10:13:59 AM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
  INFO: HHH000046: Connection properties: {user=root, password=****}
  Aug 14, 2014 10:13:59 AM org.hibernate.dialect.Dialect &lt;init&gt;
  INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect
  Aug 14, 2014 10:13:59 AM org.hibernate.engine.transaction.internal.TransactionFactoryInitiator initiateService
  INFO: HHH000399: Using default transaction strategy (direct JDBC transactions)
  Aug 14, 2014 10:13:59 AM org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory &lt;init&gt;
  INFO: HHH000397: Using ASTQueryTranslatorFactory
  Aug 14, 2014 10:14:00 AM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
  INFO: HHH000228: Running hbm2ddl schema update
  Aug 14, 2014 10:14:00 AM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
  INFO: HHH000102: Fetching database metadata
  Aug 14, 2014 10:14:00 AM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
  INFO: HHH000396: Updating schema
  Aug 14, 2014 10:14:00 AM org.hibernate.tool.hbm2ddl.DatabaseMetadata getTableMetadata
  INFO: HHH000262: Table not found: bankbranchcontactdetails
  Aug 14, 2014 10:14:00 AM org.hibernate.tool.hbm2ddl.DatabaseMetadata getTableMetadata
  INFO: HHH000262: Table not found: bankbranchcontactdetails
  Aug 14, 2014 10:14:00 AM org.hibernate.tool.hbm2ddl.DatabaseMetadata getTableMetadata
  INFO: HHH000262: Table not found: bankbranchcontactdetails
  Aug 14, 2014 10:14:00 AM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
  ERROR: HHH000388: Unsuccessful: create table stserptest.bankbranchcontactdetails (BankBranchContactId INT(10) UNSIGNED not null auto_increment, BankBranchId INT(10) UNSIGNED not null, Contact VARCHAR(20) not null, ContactTypeModified ENUM('PHONE','MOBILE','FAX','TELEX') not null, EntryDate TIMESTAMP, MyCompanyId INT(10) UNSIGNED not null, NewField INT(10) UNSIGNED, UserId INT(10) UNSIGNED, isDeleted ENUM('YES','NO'), primary key (BankBranchContactId))
  Aug 14, 2014 10:14:00 AM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
  ERROR: Table 'bankbranchcontactdetails' already exists
  Aug 14, 2014 10:14:00 AM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
  INFO: HHH000232: Schema update complete
  Aug 14, 2014 10:14:00 AM org.hibernate.cfg.Configuration configure
  INFO: HHH000043: Configuring from resource: /hibernate.cfg.xml
  Aug 14, 2014 10:14:00 AM org.hibernate.cfg.Configuration getConfigurationInputStream
  INFO: HHH000040: Configuration resource: /hibernate.cfg.xml
  Aug 14, 2014 10:14:00 AM org.hibernate.internal.util.xml.DTDEntityResolver resolveEntity
  WARN: HHH000223: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!
  Aug 14, 2014 10:14:00 AM org.hibernate.cfg.Configuration doConfigure
  INFO: HHH000041: Configured SessionFactory: null
  Aug 14, 2014 10:14:00 AM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
  INFO: HHH000402: Using Hibernate built-in connection pool (not for production use!)
  Aug 14, 2014 10:14:00 AM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
  INFO: HHH000115: Hibernate connection pool size: 20
  Aug 14, 2014 10:14:00 AM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
  INFO: HHH000006: Autocommit mode: false
  Aug 14, 2014 10:14:00 AM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
  INFO: HHH000401: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql://localhost:3306/mysql?zeroDateTimeBehavior=convertToNull]
  Aug 14, 2014 10:14:00 AM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
  INFO: HHH000046: Connection properties: {user=root, password=****}
  Aug 14, 2014 10:14:00 AM org.hibernate.dialect.Dialect &lt;init&gt;
  INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect
  Aug 14, 2014 10:14:00 AM org.hibernate.engine.transaction.internal.TransactionFactoryInitiator initiateService
  INFO: HHH000399: Using default transaction strategy (direct JDBC transactions)
  Aug 14, 2014 10:14:00 AM org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory &lt;init&gt;
  INFO: HHH000397: Using ASTQueryTranslatorFactory
  Aug 14, 2014 10:14:00 AM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
  INFO: HHH000228: Running hbm2ddl schema update
  Aug 14, 2014 10:14:00 AM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
  INFO: HHH000102: Fetching database metadata
  Aug 14, 2014 10:14:00 AM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
  INFO: HHH000396: Updating schema
  Aug 14, 2014 10:14:00 AM org.hibernate.tool.hbm2ddl.DatabaseMetadata getTableMetadata
  INFO: HHH000262: Table not found: bankbranchcontactdetails
  Aug 14, 2014 10:14:00 AM org.hibernate.tool.hbm2ddl.DatabaseMetadata getTableMetadata
  INFO: HHH000262: Table not found: bankbranchcontactdetails
  Aug 14, 2014 10:14:00 AM org.hibernate.tool.hbm2ddl.DatabaseMetadata getTableMetadata
  INFO: HHH000262: Table not found: bankbranchcontactdetails
  Aug 14, 2014 10:14:00 AM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
  ERROR: HHH000388: Unsuccessful: create table stserptest.bankbranchcontactdetails (BankBranchContactId INT(10) UNSIGNED not null auto_increment, BankBranchId INT(10) UNSIGNED not null, Contact VARCHAR(20) not null, ContactTypeModified ENUM('PHONE','MOBILE','FAX','TELEX') not null, EntryDate TIMESTAMP, MyCompanyId INT(10) UNSIGNED not null, NewField INT(10) UNSIGNED, UserId INT(10) UNSIGNED, isDeleted ENUM('YES','NO'), primary key (BankBranchContactId))
  Aug 14, 2014 10:14:00 AM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
  ERROR: Table 'bankbranchcontactdetails' already exists
  Aug 14, 2014 10:14:00 AM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
  INFO: HHH000232: Schema update complete
  Hibernate: 
      insert 
      into
          stserptest.bankbranchcontactdetails
          (BankBranchId, Contact, ContactTypeModified, EntryDate, MyCompanyId, NewField, UserId, isDeleted) 
      values
          (?, ?, ?, ?, ?, ?, ?, ?)
  Aug 14, 2014 10:14:00 AM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
  WARN: SQL Error: 1054, SQLState: 42S22
  Aug 14, 2014 10:14:00 AM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
  ERROR: Unknown column 'ContactTypeModified' in 'field list'
  </code></pre>