Hi Tom,
thanks for your response
> > Can you provide a more in-depth description of the mapping you are trying to > create between target_table and table_between. i.e. The classes involved and > the relevant instance variables and the tables involved. The reason I ask is > that based on your initial description, I was under the impression this is a > typical 1-M mapping, but it seems it may not be. >
public class Contact { Long id; String type,label; }
public class Address { Long id; String firstname,lastname; List <Contact> contacts; }
The Tables look like this (PostgreSQL Syntax)
CREATE TABLE contact ( id BIGSERIAL PRIMARY KEY, TEXT type, TEXT label );
CREATE TABLE person (
id BIGSERIAL PRIMARY KEY,
TEXT firstname,
TEXT lastname
);
CREATE TABLE contact_person ( contact_id BIGINT NOT NULL REFERENCES contact(id), person_id BIGINT NOT NULL REFERENCES person(id) );
So the query for the contacts of a person i have to do the following
SELECT * FROM contact c JOIN contact_person cp ON cp.contact_id = c.id WHERE cp.person_id = ?
This is indirection is used really often and it is some sort of a design standard (the reason is you can establish new relationships between tables without changing the table definition itself).
So how can I desribe this kind of relationship with the eclipselink api ? Is it possible with a OneToMany mapping
OneToManyMapping mtm = new OneToManyMapping(); mtm.setAttributeName("contacts"); mtm.setReferenceClass(Contact.class); ??? mtm.addTargetForeignKeyFieldName("contact.id", "contact_person.contact_id"); ??? ??? mtm.dontUseIndirection(); personDescriptor.addMapping(mtm); Thanks in Advance Sepp
P.S.: I also dont know who to define Postgres Secquences in eclipselink and find no help in the Web for it. Any Idea ?
Teilen Sie Ihre Erinnerungen mit jeder beliebigen Person online beliebigen Person online.
|