title: Hibernate: Unsuccessful alter table
body: <p>I am using Hibernate 4 and I wanted to quick test <code>@OrderColumn</code> annotation but I am getting the following error trying to do so:</p>
  
  <pre><code>INFO [main] (SchemaExport.java:343) - HHH000227: Running hbm2ddl schema export
  DEBUG [main] (SchemaExport.java:353) - Import file not found: /import.sql
  DEBUG [main] (SqlStatementLogger.java:104) - 
      alter table Order 
          drop 
          foreign key FK48E972E19D16493
  Hibernate: 
      alter table Order 
          drop 
          foreign key FK48E972E19D16493
  ERROR [main] (SchemaExport.java:425) - HHH000389: Unsuccessful: alter table Order drop foreign key FK48E972E19D16493
  ERROR [main] (SchemaExport.java:426) - 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 
          drop 
          foreign key FK48E972E19D16493' at line 1
  DEBUG [main] (SqlStatementLogger.java:104) - 
      drop table if exists Customer
  Hibernate: 
      drop table if exists Customer
  DEBUG [main] (SqlStatementLogger.java:104) - 
      drop table if exists Order
  Hibernate: 
      drop table if exists Order
  ERROR [main] (SchemaExport.java:425) - HHH000389: Unsuccessful: drop table if exists Order
  ERROR [main] (SchemaExport.java:426) - 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' at line 1
  DEBUG [main] (SqlStatementLogger.java:104) - 
      create table Customer (
          id integer not null auto_increment,
          primary key (id)
      )
  Hibernate: 
      create table Customer (
          id integer not null auto_increment,
          primary key (id)
      )
  DEBUG [main] (SqlStatementLogger.java:104) - 
      create table Order (
          id integer not null auto_increment,
          number varchar(255),
          customer_id integer,
          orders_index integer,
          primary key (id)
      )
  Hibernate: 
      create table Order (
          id integer not null auto_increment,
          number varchar(255),
          customer_id integer,
          orders_index integer,
          primary key (id)
      )
  ERROR [main] (SchemaExport.java:425) - HHH000389: Unsuccessful: create table Order (id integer not null auto_increment, number varchar(255), customer_id integer, orders_index integer, primary key (id))
  ERROR [main] (SchemaExport.java:426) - 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 (
          id integer not null auto_increment,
          number varchar(255),' at line 1
  DEBUG [main] (SqlStatementLogger.java:104) - 
      alter table Order 
          add index FK48E972E19D16493 (customer_id), 
          add constraint FK48E972E19D16493 
          foreign key (customer_id) 
          references Customer (id)
  Hibernate: 
      alter table Order 
          add index FK48E972E19D16493 (customer_id), 
          add constraint FK48E972E19D16493 
          foreign key (customer_id) 
          references Customer (id)
  ERROR [main] (SchemaExport.java:425) - HHH000389: Unsuccessful: alter table Order add index FK48E972E19D16493 (customer_id), add constraint FK48E972E19D16493 foreign key (customer_id) references Customer (id)
  ERROR [main] (SchemaExport.java:426) - 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 
          add index FK48E972E19D16493 (customer_id), 
          add constrain' at line 1
   INFO [main] (SchemaExport.java:405) - HHH000230: Schema export complete
  </code></pre>
  
  <p><strong>Following is the code being used:</strong></p>
  
  <p><strong>Customer.java</strong></p>
  
  <pre><code>@Entity
  public class Customer {
         private Integer id;
         private List&lt;Order&gt; orders;
  
         @Id @GeneratedValue 
         public Integer getId() { return id; }
         public void setId(Integer id) { this.id = id; }
  
         @OneToMany(mappedBy="customer")
         @OrderColumn(name="orders_index")
         public List&lt;Order&gt; getOrders() { return orders; }
         public void setOrders(List&lt;Order&gt; orders) { this.orders = orders; }
  
         public void addOrder(Order order) {
             this.orders.add(order);
             order.setCustomer(this);
         }
  }
  </code></pre>
  
  <p><strong>Order.java</strong></p>
  
  <pre><code>@Entity
  public class Order {
         private Integer id;
         private String number;
         private Customer customer;
  
         public Order() {}   
         public Order(String number) { this.number = number; }
  
  
      @Id @GeneratedValue 
         public Integer getId() { return id; }
         public void setId(Integer id) { this.id = id; }
  
         public String getNumber() { return number; }
         public void setNumber(String number) { this.number = number; }
  
         @ManyToOne
         @JoinColumn(name="customer_id")
         public Customer getCustomer() { return customer; }
         public void setCustomer(Customer customer) { this.customer = customer; }
  }
  </code></pre>
  
  <p><strong>TestClient.java</strong></p>
  
  <pre><code>public class Client {
      public static void main(String[] args) {        
          SessionFactory sessionFactory =  new AnnotationConfiguration().configure().buildSessionFactory();
          Session session = sessionFactory.openSession();
          Transaction txn = session.beginTransaction();
  
          //inserting data into tables
  
          Customer leo = new Customer();
          List&lt;Order&gt; orders = new ArrayList&lt;Order&gt;();
          Order book = new Order("1-sia-2nd-edi");
          Order mobile = new Order("2-son-wal");
          Order ipod = new Order("3-ipo-app");
          orders.add(book);orders.add(mobile);orders.add(ipod);
          leo.setOrders(orders);
  
          session.save(leo);
  
  
          //retrieving data from tables
  
          txn.commit();
          session.close();            
      }
  }
  </code></pre>
  
  <p><strong>hibernate.cfg.xml</strong></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.connection.driver_class"&gt;com.mysql.jdbc.Driver&lt;/property&gt;
    &lt;property name="hibernate.connection.password"&gt;pass&lt;/property&gt;
    &lt;property name="hibernate.connection.url"&gt;jdbc:mysql://localhost:3306/testdb&lt;/property&gt;
    &lt;property name="hibernate.connection.username"&gt;root&lt;/property&gt;
    &lt;property name="hibernate.dialect"&gt;org.hibernate.dialect.MySQLDialect&lt;/property&gt;
  
    &lt;property name="hibernate.hbm2ddl.auto"&gt;create&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;property name="hibernate.use_sql_comments"&gt;true&lt;/property&gt;
  
    &lt;mapping class="com.transbinary.entity.Customer"/&gt;
    &lt;mapping class="com.transbinary.entity.Order"/&gt;  
   &lt;/session-factory&gt;
  &lt;/hibernate-configuration&gt;
  </code></pre>
  
  <p>Could someone help me understand why am I getting that error?</p>