Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [eclipselink-users] Application Developer Responsibilities whenoverriding java.lang.Object.clone() in EclipseLink JPA mapped classes?

Hi Tom,

Thank you for the response. I did fail to note that in the context I
described, weaving is in fact enabled.

We have seen a couple of problems in the past in this area, one of which
was a couple of days ago, and I am in the process of trying to identify
the root cause of that issue. I want to first verify that it is not a
faulty clone() implementation in our code. If I can verify that, I will
attempt to get a test case together that demonstrates the issue in
EclipseLink.

Thanks,

Doug

-----Original Message-----
From: eclipselink-users-bounces@xxxxxxxxxxx
[mailto:eclipselink-users-bounces@xxxxxxxxxxx] On Behalf Of Tom Ware
Sent: Thursday, November 13, 2008 10:57 AM
To: EclipseLink User Discussions
Subject: Re: [eclipselink-users] Application Developer Responsibilities
whenoverriding java.lang.Object.clone() in EclipseLink JPA mapped
classes?

Hi Doug,

   As long as the clone methods on the targets of your relationships are

implemented correctly, you should be fine with cloning the way you
suggest.

   When weaving is enabled, EclipseLink does weave in a 
_persistence_post_clone() method.  That code is added after the call to 
super.clone() and does some clean-up of the weaved code.

Are you seeing problems?

-Tom

Gschwind, Doug wrote:
> Hello everyone,
> 
>  
> 
> I didn't find any information on the wiki on this topic, and that may 
> simply be due to no change in the contract regarding how overriding 
> implementations of clone() should be implemented in EclipseLink JPA 
> mapped classes. However, I am looking for confirmation of that.
> 
>  
> 
> Suppose I have a JPA mapped class, with relationships to other JPA 
> mapped classes as follows:
> 
>  
> 
> @Entity
> 
> public class Container extends Object
> 
> {
> 
>     @OneToOne
> 
>     private A a;
> 
>  
> 
>     @ManyToOne
> 
>     private B b;
> 
>  
> 
>     @OneToMany
> 
>     private List<C> cs;
> 
>  
> 
>     @ManyToMany
> 
>     private List<D> ds;
> 
> }
> 
>  
> 
> Now suppose I wish to create instances of Container by cloning 
> persistent instances. What I am looking for are any differences in the

> overriding clone() implementation if the Container class were defined
as 
> above, or if the Container class was not JPA mapped and had none of
the 
> above annotations. Would the following method suffice within the JPA 
> mapped Container class, assuming the overriding implementation of 
> clone() on the JPA mapped A, B, C, and D classes were equally
appropriate:
> 
>  
> 
> @Override
> 
> public Object clone()
> 
> {
> 
>     Container result = (Container) super.clone();
> 
>  
> 
>     result.a = (A) this.a.clone();
> 
>     result.b = (B) this.b.clone();
> 
>  
> 
>     result.cs = new ArrayList<C>(this.cs.size());
> 
>     for (C sourceC : this.cs)
> 
>     {
> 
>         C cloneC = (C) sourceC.clone();
> 
>         result.cs.add(cloneC);
> 
>         cloneC.setContainer(result);
> 
>     }
> 
>  
> 
>     result.ds = new ArrayList<D>(this.ds.size());
> 
>     for (D sourceD : this.ds)
> 
>     {
> 
>         D cloneD = (D) sourceD.clone();
> 
>         result.ds.add(cloneD);
> 
>         cloneD.setContainer(result);
> 
>     }
> 
> }
> 
>  
> 
> If not, what differences in the above implementation would be 
> recommended for use in the JPA mapped Container class?
> 
>  
> 
> Thanks,
> 
>  
> 
> Doug
> 
>  
> 
> 
> 
> 
> 
> 
> The contents of this electronic mail message and any attachments are
confidential, possibly privileged and intended
> for the addressee(s) only. Only the addressee(s) may read,
disseminate, retain or otherwise use this message. If
> received in error, please immediately inform the sender and then
delete this message without disclosing its contents
> to anyone.
> 
> 
>
------------------------------------------------------------------------
> 
> _______________________________________________
> eclipselink-users mailing list
> eclipselink-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users


Back to the top