java spring数据OneDomain关系IP错误

cnwbcb6i  于 2021-07-12  发布在  Java
关注(0)|答案(1)|浏览(327)

有人能帮我问一个问题吗。我在文档中创建了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;
}
7y4bm7vi

7y4bm7vi1#

我相信问题出在你身上 mappedBy 值,因为 mappedBy 应与相应类中的属性名相同,而不是与 @Table 注解。所以要解决这个问题,只需改变 mappedBy 形式 e_ordersattachedOrder

相关问题