当前位置: 代码迷 >> J2EE >> hibernate往数据库生成表时报语法异常求指导
  详细解决方案

hibernate往数据库生成表时报语法异常求指导

热度:57   发布时间:2016-04-17 23:45:06.0
hibernate往数据库生成表时报语法错误求指导
    <class name="manyToOne.Customer" table="CUSTOMER">
        <id name="customerId" type="java.lang.Integer">
            <column name="CUSTOMER_ID" />
            <generator class="native" />
        </id>
        <property name="customerName" type="java.lang.String">
            <column name="CUSTOMER_NAME" />
        </property>
    </class>
    <class name="manyToOne.Order" table="ORDER">
        <id name="orderId" type="java.lang.Integer">
            <column name="ORDER_ID" />
            <generator class="native" />
        </id>
        <property name="orderName" type="java.lang.String">
            <column name="ORDER_NAME" />
        </property>
        <many-to-one name="customer" class="manyToOne.Customer" >
            <column name="CUSTOMER_ID" />
        </many-to-one>
    </class>

报的错误:ERROR: HHH000388: Unsuccessful: create table ORDER (ORDER_ID integer not null auto_increment, ORDER_NAME varchar(255), CUSTOMER_ID integer, primary key (ORDER_ID))
八月 21, 2014 10:08:37 上午 org.hibernate.tool.hbm2ddl.SchemaUpdate execute
ERROR: 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 (
        ORDER_ID integer not null auto_increment,
        ORDER_NAME var' at line 1
八月 21, 2014 10:08:37 上午 org.hibernate.tool.hbm2ddl.SchemaUpdate execute
ERROR: HHH000388: Unsuccessful: alter table ORDER add index FK_p1xf4mmtq806hthtu6mxv2tf0 (CUSTOMER_ID), add constraint FK_p1xf4mmtq806hthtu6mxv2tf0 foreign key (CUSTOMER_ID) references CUSTOMER (CUSTOMER_ID)
八月 21, 2014 10:08:37 上午 org.hibernate.tool.hbm2ddl.SchemaUpdate execute
ERROR: 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 FK_p1xf4mmtq806hthtu6mxv2tf0 (CUSTOMER_ID), 
        ad' at line 1
------解决方案--------------------
一对多和多对一没有配置好
------解决方案--------------------
你Customer和Order都是 many-to-one么?
------解决方案--------------------
引用:
Quote: 引用:

一对多和多对一没有配置好

配好了
我把table="ORDER"改成table="ORDERS"就没错了不知道为什么

你表明是带是s的吧
------解决方案--------------------
order是关键字吧,别用和关键字类似的表名
  相关解决方案