本文介绍了Java Spring数据OneToMany关系芯片错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人可以帮忙解决一个问题.我已经按照文档中的说明构造了对象结构,但是Relationchip OneToMany无法正常工作.
Could someone please help with one question. I have made objects structure as in documentation, but relationschip OneToMany doesn't work.
Order:
- Positions
- Partners
I receiving error:
SQLSyntaxErrorException: 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)' at line 1
订单:
@Getter
@Setter
@Entity
@Table(name = "e_orders")
public class Order {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "order_id")
private int orderId;
@Column(unique = true)
private String orderNumber;
private int count;
@OneToMany(mappedBy = "e_orders", fetch = FetchType.LAZY)
private List<Partner> partners;
@OneToMany(mappedBy = "e_orders", fetch = FetchType.LAZY)
private List<Position> positions;
}
合作伙伴:
@Getter
@Setter
@Entity
@Table(name = "e_partner")
public class Partner {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "partner_id")
private int id;
private String name;
private String street;
private String city;
@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.PERSIST)
@JoinColumn(name = "order_e_id")
private Order attachedOrder;
}
位置:
@Getter
@Setter
@Entity
@Table(name = "e_position")
public class Position {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "position_id")
private int id;
private String guid;
private String posnr;
@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.PERSIST)
@JoinColumn(name = "order_e_id")
private Order attachedOrder;
}
推荐答案
我相信问题出在您的 mappedBy
值中,因为 mappedBy
的值应为与相应类中的属性名称相同,而不是 @Table
批注中的属性名称.因此,要解决此问题,只需将 mappedBy
形式的值从 e_orders
更改为 attachedOrder
I belive that the problem is in your mappedBy
values, coz the value for the mappedBy
should be the same as a property name in corresponding classes, not as in a @Table
annotation. So to fix the issue just change values in mappedBy
form e_orders
to attachedOrder
这篇关于Java Spring数据OneToMany关系芯片错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!