[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [eclipselink-users] Problems Mapping Map
|
Hi,
first of all i premise that i am not an expert, i am just learning.
The code of the classes that i use for this test is in my first
message, and this is the generated table schema by eclipselink of the
table class3_class2 that maps the Map association: (database
postgresql)
CREATE TABLE class3_class2
(
class3_id integer NOT NULL,
hm_id integer NOT NULL,
CONSTRAINT class3_class2_pkey PRIMARY KEY (class3_id, hm_id),
CONSTRAINT fk_class3_class2_class3_id FOREIGN KEY (class3_id)
REFERENCES class3 (id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT fk_class3_class2_hm_id FOREIGN KEY (hm_id)
REFERENCES class2 (id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION
)
WITH (OIDS=FALSE);
as you can see in this table there is no reference to Class1 and it
doesn't know the key of the map.
What it's strange for me is that if i use hibernate, same classes of
the test, same annotation without any hibernate extension i get this
schema generated by hibernate:
CREATE TABLE class3_class2
(
class3_id integer NOT NULL,
hm_id integer NOT NULL,
mapkey_id integer NOT NULL,
CONSTRAINT class3_class2_pkey PRIMARY KEY (class3_id, mapkey_id),
CONSTRAINT fk396040be7a38f2a7 FOREIGN KEY (class3_id)
REFERENCES class3 (id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT fk396040be80c8af1c FOREIGN KEY (hm_id)
REFERENCES class2 (id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT fk396040bed96997dd FOREIGN KEY (mapkey_id)
REFERENCES class1 (id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION
)
WITH (OIDS=FALSE);
where there is the mapkey_id column that reference to class1 and this
works when i test it.
I don't know why it is different but i want to use eclipselink not hibernate.
You asked me if Class1 and Class2 share the PK, and i am not sure to
understand what you mean, for all the entities that i map i use @Id
@GeneratedValue on the id accessor.
Can you please explain me what do you mean?
For the hashcode and equals i think is ok, Class1 and Class2 has only
a String field and i use hashcode and equals based on it.
Thanks for the help
Bye
2008/4/4, Gordon Yorke <gordon.yorke@xxxxxxxxxx>:
> JPA 1.0 does not support entities being the Key of a map but EclipseLink
> should. Do Class1 and Class2 share PK's? How would you write SQL based on
> your knowledge of the table structure? Can you provide an example? It
> appears from your your table description that your data may not support this
> type of mapping but if they do share PK's then you could map a OneToOne to
> Class1 from Class2 and use the MapKey to specify that mapping. Make sure
> that Class1 correctly implements hashcode and equals.
> --Gordon