我有一些模型类,我相信其中两个有错误的注释。但是,尽管我一直在寻找它,但我不知道如何正确地做到这一点。
这是模型类 - 我想实现一个商店可以有很多产品
店铺:
@Entity
@Table
public class Shop extends AbstractBaseDomain<Long> {
@Id
@GeneratedValue
private long shop_id;
@NotBlank
@Size(min = 2, max = 50)
@Column(name ="name")
private String name;
@NotNull
@ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name ="address")
private Address address;
@OneToMany(mappedBy = "product_id")
private List<Product> products;
}
产品:
@Entity
@Table
public class Product extends AbstractBaseDomain<Long> {
@Id
@GeneratedValue
private long product_id;
@NotBlank
@Size(min = 2, max = 50)
@Column(name ="productname")
private String productname;
@NotBlank
@Size(min = 2, max = 50)
@Column(name ="manufacturer")
private String manufacturer;
@NotNull
@Column(name ="currentPrice")
private BigDecimal currentPrice;
@ManyToOne
private Order order;
}
历史价格
@Entity
@Table
public class HistoryPrice extends AbstractBaseDomain<Long> {
@NotNull
@JoinColumn(name ="product_id")
private Product product;
@NotNull
@Column(name ="price")
private BigDecimal price;
@NotNull
@Column(name ="[from]")
private LocalDateTime from;
当我尝试
Shop shop = shopService.findShopById(id);
我总是收到错误消息,说 SQLGrammarException。
现在,我在模型类中实现了 shop_id 和 product_id,现在我收到另一条错误消息,说:
product [product_id])) 必须具有与引用的主键相同的列数 (shop [shop_id,id])
也许有人可以帮我解决这个问题。
提前致谢