users@glassfish.java.net

Re: Primary Key in ManyToMany relationship table

From: Marina Vatkina <Marina.Vatkina_at_Sun.COM>
Date: Wed, 16 Aug 2006 14:56:25 -0700

Ellen,

What tool do you use to generate db schema? I do not see any code in
the current sources that would add 'NO ACTION' statements, *and*
TopLink code converts all table and column names to caps.

thanks,
-marina

Ellen Kraffmiller wrote:
> Hi,
> I have defined two Entities with a ManyToMany relationship along the
> following lines:
>
> @Entity
> public class VDC {
> @Id private Long id;
> @ManyToMany
> @JoinTable(name="VDC_ADV_SEARCH_FIELDS",
> joinColumns=_at_JoinColumn(name="vdc_id"),
> inverseJoinColumns=_at_JoinColumn(name="study_field_id"))
> private Collection<StudyField> advSearchFields;
> ...
> }
>
> @Entity
> public class StudyField {
> @Id private Long id;
> @ManyToMany(mappedBy="advSearchFields")
> private Collection<VDC> advSearchFieldVDCs;
> ...
> }
>
> When generate a db schema from these entities, the following
> relationship table is created:
>
> CREATE TABLE vdc_adv_search_fields
> (
> vdc_id int8 NOT NULL,
> study_field_id int8,
> CONSTRAINT vdc_adv_search_fields_pkey PRIMARY KEY (vdc_id),
> CONSTRAINT fk_vdc_adv_search_fields_study_field_id FOREIGN KEY
> (study_field_id)
> REFERENCES studyfield (id) MATCH SIMPLE
> ON UPDATE NO ACTION ON DELETE NO ACTION,
> CONSTRAINT fk_vdc_adv_search_fields_vdc_id FOREIGN KEY (vdc_id)
> REFERENCES vdc (id) MATCH SIMPLE
> ON UPDATE NO ACTION ON DELETE NO ACTION
> )
> WITHOUT OIDS;
> ALTER TABLE vdc_adv_search_fields OWNER TO "vdcApp";
>
> My question is, why is the primary key defined only on vdc_id? I
> believe the primary key should be composed of vdc_id and study_field_id.
> Is there something I need to change on my mapping?
>
> I am running on Glassfish (Sun App Server 9.0 build b06) and using
> PostrgeSQL database.
>
> Thanks
> Ellen
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>