[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
RE: [eclipselink-users] customize OneToMany Mapping
|
This issue seems to be your adding of multiple tables to the descriptor, you
should not be doing this.
wptBestellungenDescriptor.addTableName("WPT_BESTELLPOSTEN_LISTE");
postenDescriptor.addTableName("WPT_BESTELLUNGEN"); // 1
Robert Wimmer wrote:
>
>
>>
>> Where do the tables T1, and T2 come from, is Posten using multiple tables
>> or
>> inheritance? Please include its mappings, they may be wrong. The m-m
>> join
>> looks correct.
>
> here is the full mapping declaration
> where ClassBuilderUtil.createClassDescriptor is a simple helper for
> generating ClassDescriptor
> /*
> public static RelationalDescriptor createClassDescriptor(Class <?>
> guard,
> String schema,String table,String primaryKey,
> MappingDescriptor ...descriptions)
>
> */
> and MappingDesriptor is an abstract baseClass for generating fieldmappings
>
> ....
>
>
> ClassDescriptor wptBestellungenDescriptor =
> ClassBuilderUtil.createClassDescriptor(
> WptBestellungen.class,
> null,"WPT_BESTELLUNGEN","TID",
> new DirectMappingDescriptor("tid","WPT_BESTELLUNGEN.TID")
> );
>
> ClassDescriptor bestellerDescriptor =
> ClassBuilderUtil.createClassDescriptor(
> Besteller.class,
> null,"RELAT_INFO_APPNAME_LISTE","TID",
> new DirectMappingDescriptor("tid","TID"),
> new DirectMappingDescriptor("entry","EINTRAG")
> );
>
> ClassDescriptor postenDescriptor =
> ClassBuilderUtil.createClassDescriptor(
> Posten.class,
> null,"WPT_BESTELLPOSTEN_LISTE","TID",
> new
> DirectMappingDescriptor("tid","WPT_BESTELLPOSTEN_LISTE.TID"),
> new DirectMappingDescriptor("entry","EINTRAG")
> );
>
> wptBestellungenDescriptor.addTableName("WPT_BESTELLPOSTEN_LISTE");
> postenDescriptor.addTableName("WPT_BESTELLUNGEN"); // 1
>
> OneToOneMapping mapping = new OneToOneMapping();
> mapping.setAttributeName("besteller");
> mapping.setReferenceClass(Besteller.class);
>
> mapping.addForeignKeyFieldName("WPT_BESTELLUNGEN.RELATIONEN_INFO_ID",
> "RELAT_INFO_APPNAME_LISTE.TID");
> mapping.dontUseIndirection();
> wptBestellungenDescriptor.addMapping(mapping);
>
> 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);
>
> Project sample = ProjectBuilder.createProject("WptBestellungen");
> sample.addDescriptor(wptBestellungenDescriptor);
> sample.addDescriptor(bestellerDescriptor);
> sample.addDescriptor(postenDescriptor);
> sample.setLogin(applyLogin());
> return sample;
>
> ad 1 ) "postenDescriptor.addTableName("WPT_BESTELLUNGEN");" with a lot try
> and error i found out this mapping would not work withotu this
>
> regards sepp
>
>> > 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
>> >
>
>
-----
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/customize-OneToMany-Mapping-tp24568733p25043294.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.