The JPA 1.0 spec does not support having a Map key be a separate class or
value; it must be contained in the target (value) class in JPA (and in
TopLink Essentials). What you are seeing in Hibernate is their extension of
JPA to support this.
Your best solution that is compliant with JPA is to create a class that
models the many to many join table. i.e. create a MyAssociation class that
has a OneToOne to your Map key and value, and a ManyToOne back to your
source class. Your source class will then have a OneToMany to the
association class, it can still use a Map and use the key you desire, but
the value will be the association class.
More more details see:
http://en.wikibooks.org/wiki/Java_Persistence/ManyToMany#Mapping_a_Join_Table_with_Additional_Columns
fedr wrote:
>
> I am not sure to understand what information you asked me, but to show you
> what i mean this is the database schema of class2_class3 that define the
> association in the map
>
> 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);
>
>
> if you see there is no reference to Class1.
>
> But if i try to generate the schema with hibernate, same database, same
> classes, i get this one :
>
> 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, as you can see, there is the mapkey_id column that reference to
> Class1 id and with this it works.
>
> But i want to use toplink not hibernate, i don't know why it is different,
> the code of the classes is the same, like the annotation that i used.
>
> Thanks for the help
> Bye
>
>
-----
---
http://wiki.eclipse.org/User:James.sutherland.oracle.com James Sutherland
http://www.eclipse.org/eclipselink/
EclipseLink , http://www.oracle.com/technology/products/ias/toplink/
TopLink
Wiki: http://wiki.eclipse.org/EclipseLink EclipseLink ,
http://wiki.oracle.com/page/TopLink TopLink
Forums: http://forums.oracle.com/forums/forum.jspa?forumID=48 TopLink ,
http://www.nabble.com/EclipseLink-f26430.html EclipseLink
Book: http://en.wikibooks.org/wiki/Java_Persistence Java Persistence
--
View this message in context: http://www.nabble.com/Problems-Mapping-Map-tp16468447p16537407.html
Sent from the java.net - glassfish persistence mailing list archive at Nabble.com.