From: Alex L. <lou...@ua...> - 2002-12-31 12:20:40
|
Hello Frank, see my answer below. Tuesday, December 31, 2002, 2:06:52 PM, you wrote: LF> I have two beans Feature and FeatureOption with CMR. LF> JBoss-HEAD created the tables correct, using the new feature to have the LF> same field as FK to parent and part of PK: LF> create table feature ( feature_id smallint not null, description LF> varchar(30), primary key (feature_id) constraint pk_feature ); LF> create table feature_option ( feature_id smallint not null, LF> option_id integer not null, description varchar(30), primary key LF> (feature_id,option_id) constraint pk_feature_option ); LF> alter table feature_option add constraint (foreign key (feature_id) LF> references feature constraint fk_featur_1isvfy8); LF> But everytime I try to add FeatureOptions to Feature, I get an Exception: LF> java.lang.IllegalStateException: CMR field Feature_options is mapped LF> to a foreign key which is a part for a primary key, LF> and primary key may only be set once in ejbCreate [EJB 2.0 Spec.10.3.5]. LF> My code looks like this: LF> feature = featureHome.create( feature_id, description ); LF> coll = feature.getOptions(); LF> featureOption = featureOptionHome.create( feature_id, option_id, LF> description ); LF> coll.add( featureOption ); // this line throws the exception. LF> So my Question is: How to add a FeatureOption to Feature ? This is the expected behaviour. In this case, the relationships are assigned between ejbCreate and ejbPostCreate. Having the same values in pk field and the corresponding fk field means having a relationship. Any attempt to modify the relationship with CMR accessors or with collection api will throw this exception. The relationship is removed only with one of the participant removal. Do you think it should work other way? alex |