You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by sa...@paretopartners.com on 2011/03/23 12:41:42 UTC

Transient One to One

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.

Re: Transient One to One

Posted by Kevin Sutter <kw...@gmail.com>.
Maybe I'm just being dense this afternoon, but I'm not following what PK
relationships you are trying to map.  Can you provide any type of pictures,
even cryptic stick diagrams would help.  And, exactly is your goal?  Thanks.

Kevin

On Wed, Mar 23, 2011 at 6:41 AM, <sa...@paretopartners.com> 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.

Re: Transient One to One

Posted by Matthew Adams <ma...@matthewadams.me>.
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,  <sa...@paretopartners.com> 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:matthew@matthewadams.me
skype:matthewadams12
yahoo:matthewadams
aol:matthewadams12
google-talk:matthewadams12@gmail.com
msn:matthew@matthewadams.me
http://matthewadams.me
http://www.linkedin.com/in/matthewadams