Receiving Error: 1064 on oneToMany mapping

Receiving Error: 1064 on oneToMany mapping

以下是我的客户class的DTO对象。当我在 hibernate 上进行一些查询时,我收到 1064 错误

@Entity
@Table(name="customer")
public class Customer implements Serializable{

/**
 * 
 */
private static final long serialVersionUID = 1L;

@Id
@GeneratedValue
private int id;

@Column(name="code")
private String code;

@Column(name="address")
private String address;

@Column(name="phone1")
private String phone1;

@Column(name="phone2")
private String phone2;

@Column(name="credit_limit")
private BigDecimal creditLimit;

@Column(name="current_credit")
private BigDecimal currentCredit;

@OneToMany(fetch=FetchType.EAGER)
@JoinColumn(name="customer_id")
private Set<Order> orders;}

然后我调用下面的方法

public List<Order> allOrders(){
    return orderDao.findAll();
}

这是我收到的错误。

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 orders0_ where orders0_.customer_id=5' at line 1
Hibernate: 
select
    customer0_.id as id1_0_,
    customer0_.address as address2_0_,
    customer0_.code as code3_0_,
    customer0_.credit_limit as credit_l4_0_,
    customer0_.current_credit as current_5_0_,
    customer0_.phone1 as phone6_0_,
    customer0_.phone2 as phone7_0_ 
from
    customer customer0_
Hibernate: 
select
    orders0_.customer_id as customer2_0_0_,
    orders0_.id as id1_1_0_,
    orders0_.id as id1_1_1_,
    orders0_.customer_id as customer2_1_1_ 
from

order orders0_ where
    orders0_.customer_id=?

你能告诉我这里做错了什么吗

问题是您的 Order 实体:order 是 sql 中的保留字。最好是将 table 名称更改为其他名称,例如@Table(name = "orders") - s.

或者,参见 this 答案:

If you are using Hibernate 3.5+, try hibernate.globally_quoted_identifiers=true to quote all database identifiers (this is something they added for JPA 2.0, see the secion 2.13 Naming of Database Objects of the spec for the JPA way to activate this if you are using JPA).