Java Spring Data OneToMany relationschip 错误
Java Spring Data OneToMany relationschip Error
有人能帮忙解答一个问题吗?我已按照文档中的方式制作对象结构,但 relationschip OneToMany 不起作用。
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
有人能帮忙解答一个问题吗?我已按照文档中的方式制作对象结构,但 relationschip OneToMany 不起作用。
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