title: to save very basic column values to my order table via hibernate
body: <p>I am trying to save very basic column values to my order table via hibernate. The columns are Customer no,[enter image description here][1] an integer type.I have created my order class and included the annotations. not sure where is the syntax error in my SQL. Please help. </p>
  
  <p>the main class file looks good.
  The DB connection is successful!
  not sure when I try to save the object, it throws a SQL syntax error.</p>
  
  <p>thanks! Please find my POJO and relevant mappings/annotations.</p>
  
  <p>this is my Order Class: import javax.persistence.Column;</p>
  
  <pre><code>import javax.persistence.Entity;
  import javax.persistence.GeneratedValue;
  import javax.persistence.GenerationType;
  import javax.persistence.Id;
  import javax.persistence.Table;
  
  @Entity
  @Table(name="ORDER")
  public class Order {
  
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      @Column(name="Order_no")
      private int _OrderNo;
  
  
  
      @Column(name="Customer_no")
      private int _CustomerNo;
  
      public Order() {
  
      }
  
      public Order(int CustomerNo) {
  
  
          this._CustomerNo = CustomerNo;
      }
  
  
  
      public int get_OrderNo() {
          return _OrderNo;
      }
  
      public void set_OrderNo(int OrderNo) {
          this._OrderNo = OrderNo;
      }
  
  
      public int get_CustomerNo() {
          return _CustomerNo;
      }
  
      public void set_CustomerNo(int CustomerNo) {
          this._CustomerNo = CustomerNo;
      }
  
      @Override
      public String toString() {
          return "Order [_OrderNo=" + _OrderNo + ",  _CustomerNo=" + _CustomerNo + "]";
      }
  
  }  
  </code></pre>
  
  <hr>
  
  <p>this is my actual object saving file.</p>
  
  <pre><code>public class CreateOrder {
  
      public static void main(String[] args) {
  
  
          SessionFactory factory = new Configuration().configure("hibernate.cfg.xml").addAnnotatedClass(Order.class)
                  .buildSessionFactory();
  
  
  
          Session session = factory.getCurrentSession();
  
          try {
  
  
  
              System.out.println("Creating the Order Object.......");
  
              Order tempOrder = new Order(123);
  
  
              session.beginTransaction();
  
  
              System.out.println("Saving the Order ");
              session.save(tempOrder);
  
  
              session.getTransaction().commit();
              System.out.println("Done!!");
          }
  
          finally {
              factory.close();
          }
      }
  
  }
  </code></pre>
  
  <hr>
  
  <pre><code>&lt;!DOCTYPE hibernate-configuration PUBLIC
          "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
          "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"&gt;
  
  &lt;hibernate-configuration&gt;
  
      &lt;session-factory&gt;
  
          &lt;!-- JDBC Database connection settings --&gt;
          &lt;property name="connection.driver_class"&gt;com.mysql.jdbc.Driver&lt;/property&gt;
          &lt;property name="connection.url"&gt;jdbc:mysql://localhost:3306/hb_student_retail?useSSL=false&lt;/property&gt;
          &lt;property name="connection.username"&gt;hbstudent&lt;/property&gt;
          &lt;property name="connection.password"&gt;hbstudent&lt;/property&gt;
  
          &lt;!-- JDBC connection pool settings ... using built-in test pool --&gt;
          &lt;property name="connection.pool_size"&gt;1&lt;/property&gt;
  
          &lt;!-- Select our SQL dialect --&gt;
          &lt;property name="dialect"&gt;org.hibernate.dialect.MySQLDialect&lt;/property&gt;
  
          &lt;!-- Echo the SQL to stdout --&gt;
          &lt;property name="show_sql"&gt;true&lt;/property&gt;
  
          &lt;!-- Set the current session context --&gt;
          &lt;property name="current_session_context_class"&gt;thread&lt;/property&gt;
  
      &lt;/session-factory&gt;
  
  &lt;/hibernate-configuration&gt;
  </code></pre>
  
  <hr>
  
  <p>pls find here the stacktrace </p>
  
  <pre><code>:Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not execute statement
      at org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:63)
      at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:42)
      at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:111)
      at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:97)
      at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:208)
      at org.hibernate.dialect.identity.GetGeneratedKeysDelegate.executeAndExtract(GetGeneratedKeysDelegate.java:57)
      at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:42)
      at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2909)
      at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3480)
      at org.hibernate.action.internal.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:81)
      at org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:626)
      at org.hibernate.engine.spi.ActionQueue.addResolvedEntityInsertAction(ActionQueue.java:280)
      at org.hibernate.engine.spi.ActionQueue.addInsertAction(ActionQueue.java:261)
      at org.hibernate.engine.spi.ActionQueue.addAction(ActionQueue.java:306)
      at org.hibernate.event.internal.AbstractSaveEventListener.addInsertAction(AbstractSaveEventListener.java:318)
      at org.hibernate.event.internal.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:275)
      at org.hibernate.event.internal.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:182)
      at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:113)
      at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:192)
      at org.hibernate.event.internal.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:38)
      at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:177)
      at org.hibernate.event.internal.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:32)
      at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:73)
      at org.hibernate.internal.SessionImpl.fireSave(SessionImpl.java:689)
      at org.hibernate.internal.SessionImpl.save(SessionImpl.java:681)
      at org.hibernate.internal.SessionImpl.save(SessionImpl.java:676)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:498)
      at org.hibernate.context.internal.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:355)
      at com.sun.proxy.$Proxy28.save(Unknown Source)
      at com.mrunalini.demoApril20.hibernateEntities.CreateOrder.main(CreateOrder.java:34)
  Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ORDER (Customer_no) values (123)' at line 1
      at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
      at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
      at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
      at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
      at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
      at com.mysql.jdbc.Util.getInstance(Util.java:408)
      at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:944)
      at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3976)
      at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3912)
      at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2530)
      at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2683)
      at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2486)
      at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1858)
      at com.mysql.jdbc.PreparedStatement.executeUpdateInternal(PreparedStatement.java:2079)
      at com.mysql.jdbc.PreparedStatement.executeUpdateInternal(PreparedStatement.java:2013)
      at com.mysql.jdbc.PreparedStatement.executeLargeUpdate(PreparedStatement.java:5104)
      at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1998)
      at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:205)
      ... 28 more
  </code></pre>