Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] JPA Mapping - OneToMany (EclipseLink 1.02 , 1.1)

Maybe I'm missing something, but this is how I do @OneToMany's

In your Person:
@OneToMany(mappedBy="PKEY")
private List<Phone> phoneList;

In Phone:
@ManyToOne
@JoinColumn(name="PKEY")
private Person pkey;

Why wouldn't this work?

./tch



On Mon, Jan 12, 2009 at 6:47 AM, Robert Lalyko <robert.lalyko@xxxxxxxxx> wrote:
> Hi,
>  by using the EclipseLink JPA annotation mapping I have had problems to
> create an unidirectional one-to-many mapping:
>
> The entity 'Person' contains the attribute 'phoneList' (entity: Phone).
> The 'PHONE' database table contains the column 'PKEY' to refer the 'Person'
> entity/table,
> but I won't have an attribute in the entity 'Phone' to refer the
> 'Person' entity.
> (There should be only an unidirectional one-to-many relationship without a
> join table .)
>
> If I don't use a join table, the eclipse compiler return the error message:
>     Join table "PERSON_PHONE" cannot be
> resolved Person.java AddressBook-JPA/src/org/addressbook/data line 49 JPA
> Problem Marker
>
> I tried to define this mapping by using EclipseLink 1.02 and 1.1 current
> snapshot.
>
> I found a tricky solution for this problem by using the target table to join
> .
>
> @JoinTable(name="PHONE",schema="ADDRESSBOOK", joinColumns =
> {@JoinColumn(name="PKEY", referencedColumnName = "PKEY")},
> inverseJoinColumns = @JoinColumn(name="PHKEY", referencedColumnName =
> "PHKEY"))
>
> But this produces a double select query of the target table:
>
> SELECT t1.PHKEY, t1.ARCODE, t1.PHNBR, t1.PHCCODE, t1.TCODE
>
> FROM ADDRESSBOOK.PHONE t0, ADDRESSBOOK.PHONE t1
>
> WHERE ((t0.PKEY = ?) AND (t1.PHKEY = t0.PHKEY))
>
> And finally I have problems to persist the data, cause EclipseLink tries to
> insert join
> table records. (org.eclipse.persistence.exceptions.DatabaseException by
> 'Insert JoinTable Exception')
>
> DataModifyQuery(sql="INSERT INTO ADDRESSBOOK.PHONE (PHKEY, PKEY) VALUES (?,
> ?)")
>
> So this isn't a useful way to define a one-to-many mappings ...
>
> At the EclipseLink site I found an article (JPA2.0 issue) about
> 'unidirectional one-to-many'.
>
> ? Is the unidirectional one-to-many JPA mapping without @JoinTable not
> available by JPA 1.0 really?
>
> ? Will there be the support of a JPA mapping with target tables by
> EclipseLink 1.1 (Release)?
>
> Thanks,
> Robert
>
> _______________________________________________
> eclipselink-users mailing list
> eclipselink-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
>
>


Back to the top