我正在学习 Spring-Data-REST 并且遇到了涉及我的注释的障碍。目前我有以下架构:
create table user
(
ID int NOT NULL auto_increment,
NAME VARCHAR(60) NOT NULL,
PASS VARCHAR(20) NOT NULL,
primary key (ID)
);
create table recipe
(
ID int NOT NULL auto_increment,
NAME varchar(60) NOT NULL,
USER_ID int NOT NULL,
primary key (ID),
FOREIGN KEY (USER_ID) REFERENCES user(ID) ON DELETE CASCADE
);
create table ingredient
(
ID int not null auto_increment,
NAME varchar(60) not null,
primary key(ID)
);
create table ingredientsList
(
ID int NOT NULL auto_increment,
NAME varchar(60) NOT NULL,
RECIPE_ID int not null,
INGREDIENT_ID int not null,
QUANTITY int not null,
primary key (ID),
foreign key (RECIPE_ID) REFERENCES recipe(ID) on delete cascade,
foreign key (INGREDIENT_ID) references ingredient(ID) on delete cascade
);
create table direction
(
ID int NOT NULL auto_increment,
NAME varchar(60) NOT NULL,
RECIPE_ID int not null,
STEP int not null,
DESCRIPTION varchar(256),
primary key (ID),
foreign key (RECIPE_ID) REFERENCES recipe(ID) on delete cascade
);
我的 Spring Data REST API 中表示了每个表,除了一个表,即成分列表表。这是我当前的实现,当我运行 .\mvn clean install 时无法正常工作:
import java.util.Objects;
import java.util.Set;
import javax.persistence.Column;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
@Entity
public class IngredientsList extends AbstractEntity {
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(nullable=false)
private Recipe recipe;
@OneToMany(mappedBy = "ingredientsList", fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true)
private Set<Ingredient> ingredients;
@Column(nullable = false)
private Long quantity;
public Recipe getRecipe() {
return recipe;
}
public void setRecipe(Recipe recipe){
this.recipe = recipe;
}
森栏
相关分类