Hello!
I have two classes, the one is named Group, the other BaseFeature. now, i want that the class group is persisting several objects of the BaseFeature class as a map (list).
@Entity(name = "`group`") public class Group {
private Map<String, BaseFeature> baseFeatures; @ElementCollection public Map<String, BaseFeature> getBaseFeatures() { return baseFeatures; } }
If am adding now several baseFeatures to a group X and persisting group X, it works. but if i am now adding the same baseFeatures to group Y, an exception is thrown:
org.postgresql.util.PSQLException: ERROR: duplicate key value violates unique constraint "group_BaseFeature_basefeatures_id_key" Detail: Key (basefeatures_id)=(12) already exists.
Group_id [PK] bigint; basefeatures_id bigint; basefeatures_key [PK] character varying (255) 90;12;"Age" 90;10;"Emotion" 90;13;"Gender" 90;11;"Relationship" 90;14;"Wealth" 90;16;"WeatherDegree" 90;15;"WeatherType"
the generated table syntax looks like this, and i think that the problem is the last line, marked bold:
CREATE TABLE "group_BaseFeature" ( "Group_id" bigint NOT NULL, basefeatures_id bigint NOT NULL, basefeatures_key character varying(255) NOT NULL, CONSTRAINT "group_BaseFeature_pkey" PRIMARY KEY ("Group_id" , basefeatures_key ), CONSTRAINT fkfe462505436784f6 FOREIGN KEY (basefeatures_id) REFERENCES basefeature (id) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION, CONSTRAINT fkfe46250546aa625f FOREIGN KEY ("Group_id") REFERENCES "group" (id) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION, CONSTRAINT "group_BaseFeature_basefeatures_id_key" UNIQUE (basefeatures_id ) )
I dont understand why group_BaseFeature_basefeatures_id_key is generated as UNIQUE, nor, how to solve my problem. thx for any help..
alex
|