title: java hibernate error "could not execute statement" in Session.save()
body: <pre><code>/**
   * Description of bankbranchcontactdetailsBean
   *
   * @author Vishal Jain
   */
  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.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 {
  
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      @Column(columnDefinition = "mysql-&gt;int(10) unsigned", name = "BankBranchContactId", precision = 10, scale = 0, nullable = false, unique = true)
      private Integer _BankBranchContactId;
  
      @Column(columnDefinition = "mysql-&gt;int(10) unsigned", name = "BankBranchId", precision = 10, scale = 0, nullable = false)
      private Integer _BankBranchId;
  
      @Column(columnDefinition = "mysql-&gt;enum('Phone','Mobile','Fax','Telex')", name = "ContactType", length = 6, nullable = false)
      private String _ContactType;
  
      @Column(columnDefinition = "mysql-&gt;varchar(20)", name = "Contact", length = 20, nullable = false)
      private String _Contact;
  
      public bankbranchcontactdetailsBean() {
  
          _BankBranchId = 0;
          _ContactType = "";
          _Contact = "";
      }
  
      public bankbranchcontactdetailsBean(Integer __BankBranchId,
              String __ContactType, String __Contact) {
  
          _BankBranchId = __BankBranchId;
          _ContactType = __ContactType;
          _Contact = __Contact;
      }
  
      public Integer getBankBranchId() {
          return _BankBranchId;
      }
  
      public String getContactType() {
          return _ContactType;
      }
  
      public String getContact() {
          return _Contact;
      }
  
      public void setBankBranchId(Integer NewValue) {
          _BankBranchId = NewValue;
      }
  
      public void setContactType(String NewValue) {
          _ContactType = NewValue;
      }
  
      public void setContact(String NewValue) {
          _Contact = NewValue;
      }
  
  }
  
  /**
    * Description of hibernate.cfg.xml
    */
  &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;password&lt;/property&gt;
          &lt;property name="hibernate.default_schema"&gt;v32&lt;/property&gt;
          &lt;property name="hibernate.hbm2ddl.auto"&gt;update&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 {
  }
  
  
  OUTPUT
  
      enter code here
  
  ClassName -- FileName -- MethodName -- LineNo.
  org.hibernate.exception.internal.SQLExceptionTypeDelegate -- SQLExceptionTypeDelegate.java -- convert -- 82
  org.hibernate.exception.internal.StandardSQLExceptionConverter -- StandardSQLExceptionConverter.java -- convert -- 49
  org.hibernate.engine.jdbc.spi.SqlExceptionHelper -- SqlExceptionHelper.java -- convert -- 125
  org.hibernate.engine.jdbc.spi.SqlExceptionHelper -- SqlExceptionHelper.java -- convert -- 110
  org.hibernate.engine.jdbc.internal.ResultSetReturnImpl -- ResultSetReturnImpl.java -- executeUpdate -- 136
  org.hibernate.id.IdentityGenerator$GetGeneratedKeysDelegate -- IdentityGenerator.java -- executeAndExtract -- 96
  org.hibernate.id.insert.AbstractReturningDelegate -- AbstractReturningDelegate.java -- performInsert -- 58
  org.hibernate.persister.entity.AbstractEntityPersister -- AbstractEntityPersister.java -- insert -- 2975
  org.hibernate.persister.entity.AbstractEntityPersister -- AbstractEntityPersister.java -- insert -- 3487
  org.hibernate.action.internal.EntityIdentityInsertAction -- EntityIdentityInsertAction.java -- execute -- 81
  org.hibernate.engine.spi.ActionQueue -- ActionQueue.java -- execute -- 377
  org.hibernate.engine.spi.ActionQueue -- ActionQueue.java -- addResolvedEntityInsertAction -- 214
  org.hibernate.engine.spi.ActionQueue -- ActionQueue.java -- addInsertAction -- 194
  org.hibernate.engine.spi.ActionQueue -- ActionQueue.java -- addAction -- 178
  org.hibernate.event.internal.AbstractSaveEventListener -- AbstractSaveEventListener.java -- addInsertAction -- 321
  org.hibernate.event.internal.AbstractSaveEventListener -- AbstractSaveEventListener.java -- performSaveOrReplicate -- 286
  org.hibernate.event.internal.AbstractSaveEventListener -- AbstractSaveEventListener.java -- performSave -- 192
  org.hibernate.event.internal.AbstractSaveEventListener -- AbstractSaveEventListener.java -- saveWithGeneratedId -- 125
  org.hibernate.event.internal.DefaultSaveOrUpdateEventListener -- DefaultSaveOrUpdateEventListener.java -- saveWithGeneratedOrRequestedId -- 206
  org.hibernate.event.internal.DefaultSaveEventListener -- DefaultSaveEventListener.java -- saveWithGeneratedOrRequestedId -- 55
  org.hibernate.event.internal.DefaultSaveOrUpdateEventListener -- DefaultSaveOrUpdateEventListener.java -- entityIsTransient -- 191
  org.hibernate.event.internal.DefaultSaveEventListener -- DefaultSaveEventListener.java -- performSaveOrUpdate -- 49
  org.hibernate.event.internal.DefaultSaveOrUpdateEventListener -- DefaultSaveOrUpdateEventListener.java -- onSaveOrUpdate -- 90
  org.hibernate.internal.SessionImpl -- SessionImpl.java -- fireSave -- 764
  org.hibernate.internal.SessionImpl -- SessionImpl.java -- save -- 756
  com.stserp.beans.ManagerClass -- ManagerClass.java -- SaveBeansList -- 60
  com.stserp.Program -- Program.java -- main -- 73
  
  could not execute statement
  </code></pre>
  
  <p>Please help me with the Code as I cannot understand why am I getting this <code>"could not execute statement" error.</code></p>
  
  <p>I have tried many things, but none of it worked. Some article even suggested to use <code>@cascade = {cascadeType = SAVE_UPDATE}</code> but I don't want to link my table to any other table. I am supposed to maintain all the relations in my code only. There must be some way where tables, if not related to any other table, can be saved. Please help.</p>