以下是我的客户类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=?
你能说出我在这里做错了吗
答案 0 :(得分:2)
问题是你的Order
实体:order
是sql中的保留字。最好是将表名更改为其他名称,例如@Table(name = "orders")
- s
。
或者,请参阅this回答:
如果您使用的是Hibernate 3.5+,请尝试 hibernate.globally_quoted_identifiers = true引用所有数据库 标识符(这是他们为JPA 2.0添加的内容,请参阅secion 2.13如果使用JPA,JPA命名的数据库对象的命名为JPA方式激活它。