-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Annotating a Map with @ElementCollection
PostPosted: Fri Nov 02, 2012 5:32 pm 
Newbie

Joined: Wed Jun 11, 2008 1:01 pm
Posts: 3
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.