persistence@glassfish.java.net

Re: Primary Key references entity

From: Gordon Yorke <gordon.yorke_at_ORACLE.COM>
Date: Thu, 12 Jun 2008 10:47:17 -0400

Support for this functionality will be in JPA 2.0. (The details can be
seen in the early draft
http://jcp.org/aboutJava/communityprocess/edr/jsr317/index.html ).

In TopLink it is possible to do this as James mentioned but it is also
possible to get the same functionality in JPA 1.0 by creating an
attribute in the Entity for the FK/PK field and marking it @Id and as
updatable=false, insertable=false. Then simply put the @OneToOne mapping
on the actual relationship. Be sure to set the new attribute id value
when the MyMasterEntity is set on this Entity. This will also provide
you with a straight forward mechanism for creating the PKClass.
--Gordon

Markus Karg wrote:
>
> We need to have a entity primary key pointing to another entity
> (typical master-detail construction).
>
>
>
> Is it possible to do:
>
>
>
> @Id
>
> private MyMasterEntity;
>
>
>
> ?
>
>
>
> Also for legacy reasons we need a PK class. Is it possible to have
> private MyMasterEntity as a field in the PK class, or how to deal with
> that?
>
>
>
> Thanks
>
> Markus
>
>
>
> QUIPSY QUALITY GmbH & Co. KG
>
> Ein Unternehmen der MES-Gruppe
>
> Stuttgarter Strasse 23
>
> D-75179 Pforzheim
>
> Tel: 07231-9189-52
>
> Fax: 07231-9189-59
>
> www.quipsy.de <http://www.quipsy.de>
>
> karg_at_quipsy.de <mailto:karg_at_quipsy.de>
>
> Registergericht Mannheim HRA 701214
>
> Geschäftsführer: Nils Schroeder
>
>
>
> Diese E-Mail enthält persönliche, vertrauliche und vor Weitergabe
> geschützte Informationen und ist ausschließlich für den vorgesehenen
> o.g. Empfänger (Adressaten) bestimmt. Falls Sie diese E-Mail
> versehentlich erhalten haben und nicht der vorgesehene Empfänger sind,
> bitten wir Sie, die E-Mail und deren Anhänge nicht aufzubewahren,
> nicht zu vervielfältigen, nicht zu nutzen und nicht weiterzugeben.
> Bitte informieren Sie uns als Absender über diesen Zustellungsfehler
> und löschen Sie die E-Mail.
>
>
>