[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [eclipselink-users] customize OneToMany Mapping
|
Hi Sepp,
Now I understand. It was not clear from your previous description of the
problem that you want to map OneToOne mapping with a join table.
That functionality is actually very new in EclipseLink - part of our work on
the JPA 2.0 specification, but it is available on our latest stream.
Some details can be found at these links:
http://wiki.eclipse.org/EclipseLink/Development/JPA2.0/one-to-one_via_jointable
https://bugs.eclipse.org/bugs/show_bug.cgi?id=282553
Please note, this functionality is only currently available on our recent 2.0
nightly builds.
There is support for defining sequence objects, but the public access is
through our JPA DDL generation feature. For those that are not using JPA, this
is a more difficult question. It may be easier to just create them on the DB
and use them from EclipseLink. If you are set on using EclipseLink to create
sequences, there is some example code in our testing framework in our core test
framework. (org.eclipse.persistence.testing.tests.feature.OracleNativeSeqInitTest)
-Tom
Robert Wimmer wrote:
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.
<http://www.microsoft.com/austria/windows/windowslive/products/photos-share.aspx?tab=1>
------------------------------------------------------------------------
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users