I’m using Playframework 1.2.4 and PostgresSQL 9.1.2. I have the following entities: Recipe and RecipeItem. A Recipe has a set of RecipeItems. I’ve annotated the set of recipe items in the Recipe class as follows:
@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();
But when I check the PgAdmin to see if the constraint has been applied to the RecipeItemForIngredients table I cannot find it. This is what PgAdmin shows.
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)
)
Does anyone have an idea why this could be happening? Maybe this annotation is not supported by the ORM used by Playframework.
This constraint doesn’t make much sense, and you have a stronger constraint by default anyway:
If
recipeItemIdis unique, then of course, the tuple(recipeId, recipeItemId)is also unique.Moreover, since the PK of the table is
(recipeId, recipeItemId), the constraint is already applied by the PK constraint.