gpt4 book ai didi

java - 接收错误: 1064 on oneToMany mapping

转载 作者:行者123 更新时间:2023-12-02 05:04:29 24 4
gpt4 key购买 nike

以下是我的客户类 DTO 对象。当我在 hibernate 上进行一些 get 查询时,我收到 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(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).

关于java - 接收错误: 1064 on oneToMany mapping,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27919625/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com