I think what you want to do is have two fields in your referencing
object: one persistent field to hold the PK to the other object, and
one transient field to hold a reference to the object that has the PK.
Then, in a post-load callback, populate the transient reference using
the field containing the PK of the object you want to reference
transiently. You could also nullify the transient field on a
pre-detach & pre-delete as well.
public class Foo {
// ...
private BarKey barKey; // persistent, stores PK
@Transient
private Bar bar; // transient, refers to Bar with key barKey
@PostLoad
public void postLoad() {
bar = goFindBarByKey(barKey); // or however you load the Bar
}
}
-matthew
On Wed, Mar 23, 2011 at 6:41 AM, <[email protected]> wrote:
> Hello there,
>
> I have a persisted field that contains the PK of another entity. It is not
> mapped properly and is filled manually. The objects this PK refers to are
> all loaded elsewhere.
> The mappedBy seems to only apply to inverse relations. Is there a way I
> can add a Transient OneToOne field that uses this PK and points to that
> entity? (It need not be saved again...)
>
> How can I add a new field to this same object that refers to the entity
> pointed to by the PK? I know I am approaching this the wrong way, can
> anyone provide any guidance on where to go from here?
>
> Thank-you.
>
> This message may contain confidential and privileged information and is
> intended solely for the use of the named addressee. Access, copying or re-use
> of the e-mail or any information contained therein by any other person is not
> authorised. If you are not the intended recipient please notify us
> immediately by returning the e-mail to the originator and then immediately
> delete this message. Although we attempt to sweep e-mail and attachments for
> viruses, we do not guarantee that either are virus-free and accept no
> liability for any damage sustained as a result of viruses.
>
> Please refer to http://www.bnymellon.com/disclaimer/piml.html for certain
> disclosures.
--
mailto:[email protected]
skype:matthewadams12
yahoo:matthewadams
aol:matthewadams12
google-talk:[email protected]
msn:[email protected]
http://matthewadams.me
http://www.linkedin.com/in/matthewadams