0
我正在使用Playframework 1.2.4和PostgresSQL 9.1.2。我有以下實體:配方和RecipeItem。配方有一組RecipeItems。我已經詮釋了一套食譜項目在配方類,如下所示:@UniqueConstraints無法在@JoinTable上工作
@Required
@MinSize(1)
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@JoinTable(name = "RecipeItemForIngredients",
joinColumns = @JoinColumn(name = "recipeId"),
inverseJoinColumns = @JoinColumn(name = "recipeItemId"),
uniqueConstraints = @UniqueConstraint(name = "uq_recipeItemPerRecipe",
columnNames = {"recipeId", "recipeItemId"}))
public Set<RecipeItem> items = Sets.newHashSet();
但是,當我檢查pgAdmin的,看看如果約束已經被應用到RecipeItemForIngredients表我找不到它。這是PgAdmin顯示的內容。
CREATE TABLE recipeitemforingredients
(
recipeid bigint NOT NULL,
recipeitemid bigint NOT NULL,
CONSTRAINT recipeitemforingredients_pkey PRIMARY KEY (recipeid, recipeitemid),
CONSTRAINT fk5ac547a883708db FOREIGN KEY (recipeid)
REFERENCES recipe (id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT fk5ac547ad6e1da8f FOREIGN KEY (recipeitemid)
REFERENCES "recipe$recipeitem" (id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT recipeitemforingredients_recipeitemid_key UNIQUE (recipeitemid)
)
有沒有人有一個想法,爲什麼會發生這種情況?也許這個註解不被Playframework使用的ORM支持。
確定雖然配方無法重複一個成分,這要歸功於主鍵。我想知道它爲什麼決定使用主鍵而不是使用唯一的命名約束 – GuidoMB
我不知道。也許它足夠聰明以檢測重複或不必要的限制。 –