在學習hibernate一對多映射關系時,根據視頻學習的時候,例子是顧客和訂單的問題,一個顧客有多個訂單。按照視頻中的敲代碼出現了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_name, customer)
原因是order是mysql關鍵字,不能做為表名
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate Mapping DTD 3.0"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.cqupt.dayday">
<class name="Order" table="order1">
<id name="orderId" type="java.lang.Integer">
<column name="order_id"/>
<!--指定主鍵的生成方式, native:使用數據庫本地方式-->
<generator class="native"/>
</id>
<property name="orderName" type="java.lang.String">
<column name="order_name"/>
</property>
<!--映射多對一的關聯關系-->
<many-to-one name="customer" class="Customer" column="customer_id"></many-to-one>
</class>
</hibernate-mapping>
后來將表名改為table1就運行成功了
