Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [eclipselink-users] customize OneToMany Mapping

Hi Tom,

> For a OneToMany (rather than OneToOne) with a join table, just use a
> ManyToMany mapping. There should be an example of one of those in the example
> code I pointed you at earlier.

as you suggested i tried it with a ManyToManyMapping, but only with some success

my Mapping definition
...
ManyToManyMapping mmm = new ManyToManyMapping();
mmm.setAttributeName("posten");
mmm.setReferenceClass(Posten.class);
mmm.dontUseIndirection();
mmm.setRelationTableName("wpt_posten_bestellungen_lbez");
mmm.addSourceRelationKeyFieldName("wpt_posten_bestellungen_lbez.wpt_bestellungen_id","WPT_BESTELLUNGEN.TID");
mmm.addTargetRelationKeyFieldName("wpt_posten_bestellungen_lbez.wpt_bestellposten_liste_id","WPT_BESTELLPOSTEN_LISTE.TID");
wptBestellungenDescriptor.addMapping(mmm);
...

the problem is it only returns 1 row instead of multiple rows

to make it clearer some sql

-- the "handmade" query
SELECT liste.tid,liste.eintrag FROM wpt_bestellposten_liste liste
JOIN wpt_posten_bestellungen_lbez lbez  ON lbez.wpt_bestellposten_liste_id = liste.tid
JOIN wpt_bestellungen b ON lbez.wpt_bestellungen_id = b.tid
WHERE b.tid = 119.9;
-- returns 5 records (es expected)

-- eclipselink generated query
SELECT t1.TID, t2.TID, t1.EINTRAG FROM
       wpt_posten_bestellungen_lbez t0,
       WPT_BESTELLUNGEN t2,
       WPT_BESTELLPOSTEN_LISTE t1
WHERE (((t0.wpt_bestellungen_id = 119.9)
      AND (t1.TID = t0.wpt_bestellposten_liste_id))
      AND (t2.TID = t1.TID)
      );
-- returns only 1 record

-- the query eclipselink should generate
SELECT t1.TID, t2.TID, t1.EINTRAG FROM
       wpt_posten_bestellungen_lbez t0,
       WPT_BESTELLUNGEN t2,
       WPT_BESTELLPOSTEN_LISTE t1
WHERE (((t0.wpt_bestellungen_id = 119.9)
      AND (t1.TID = t0.wpt_bestellposten_liste_id))
      AND (t2.TID = t0.wpt_bestellungen_id)  -- <<< t2.TID != t1.TID  
      );

as you see the second AND _expression_ is parameterized not as expected.
I tried to rewrite the mapping in a lot of different ways, but never got the expected result.

>Before JPA, the typical way to use EclipseLink (then called TopLink) was to
>use the MappingWorkbench to describe your metadata and export either Java code
>or an XML document that contains that metadata. I realize that will not get you
>all the way to your goal. If you use the facility to export java code, it will,
>however give you a way to generate and see the type of java code that
>EclipseLink expects for its descriptors and mappings - a way to prototype.
where can I download this workbench ?

One main reason for not using JPA is, that i am not able to get it running in a simple RCP application (without any Application-Server). I found some links describing solutions for this problems but I am not able to develop sample applications with our own background. This is a lot easier using the "native" eclipse-link api.

regards

Sepp



Hol dir noch heute die neue Beta des Windows Live Messengers! Hier klicken!

Back to the top