有人能帮我问一个问题吗。我在文档中创建了objects结构,但关系chip-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;
}
1条答案
按热度按时间7y4bm7vi1#
我相信问题出在你身上
mappedBy
值,因为mappedBy
应与相应类中的属性名相同,而不是与@Table
注解。所以要解决这个问题,只需改变mappedBy
形式e_orders
至attachedOrder