【发布时间】:2018-02-25 18:41:55
【问题描述】:
我有三张桌子
CREATE TABLE "ingredient" (
"id" INTEGER GENERATED BY DEFAULT AS IDENTITY(START WITH 1, INCREMENT BY 1) PRIMARY KEY,
"ingredient" VARCHAR(50) NOT NULL
);
CREATE TABLE "pizza" (
"id" INTEGER GENERATED BY DEFAULT AS IDENTITY(START WITH 1, INCREMENT BY 1) PRIMARY KEY,
"pizza" VARCHAR(50) NOT NULL
);
CREATE TABLE "pizza_structure" (
"pizza_id" INT NOT NULL,
"ingredient_id" INT NOT NULL,
"amount" INT NOT NULL
);
如何加入他们,将 Pizzas 结构作为地图
@Entity
@Table(name = "ingredient")
public class Ingredient{
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String name;
public Ingredient() {
}
}
@Entity
@Table(name = "pizza")
public class Pizza {
@Id
@GeneratedValue
private Long id;
private String name;
@OneToMany ????
private Map<Ingredient, Integer> pizzaStructure;
public Pizza() {
}
public Pizza(String name, Map<Long, Integer> pizzaStructure) {
this.name = name;
this.pizzaStructure = pizzaStructure;
}
}
是否需要创建@Embeddable 类PizzaStructure,如果需要,何时使用?
现在我遇到了一个错误 调用 init 方法失败;嵌套异常是 org.hibernate.AnnotationException: Use of @OneToMany or @ManyToMany 针对未映射的类:
【问题讨论】: