You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openjpa.apache.org by Kevin Sutter <kw...@gmail.com> on 2007/10/04 22:00:40 UTC
Cloning Calendar proxies
Hi,
It seems that the IBM JDK is cloning a Calendar object when performing the
.equals() method. If I call .equals() on one of our Calendar proxy objects,
the underlying implementation seems to be cloning the object before
determining the equality. While using this cloned object, one of the setter
methods is called. Since this is a cloned Calendar proxy, we do some
processing to access the associated StateManager. But, that requires access
to a Broker and there is no Broker instance associated with this cloned
object and we end up throwing an IllegalStateException. Due to that
exception, the .equals() always returns false.
So, before I start experimenting with various fix strategies, I'm looking
for some guidance from the original developers...
o Should we override the clone() method? And, if we do, should we be
returning a non-proxy version of a Calendar object? Or, should we ensure
that a fully populated Calendar proxy object get returned?
o Or, should we think about overriding the .equals method on the Calendar
proxies? I'm not too thrilled with this since then we'll be attempting to
implement the javadoc for these object types.
Whatever we determine will probably apply to all of our proxy object types,
even though we're only hitting this problem with the Calendar proxy due to
the IBM JDK.
Thoughts or suggestions?
Kevin
RE: Cloning Calendar proxies
Posted by Pinaki Poddar <pp...@bea.com>.
One of the reasons of these objects being proxied is that their change
can mark the owning persistent entity as dirty.
Pinaki Poddar
972.834.2865
>-----Original Message-----
>From: Evan Ireland [mailto:eireland@sybase.com]
>Sent: Thursday, October 04, 2007 3:29 PM
>To: dev@openjpa.apache.org
>Subject: RE: Cloning Calendar proxies
>
>Just curious, why are Calendar objects being proxied in the
>first place?
>
>> -----Original Message-----
>> From: Kevin Sutter [mailto:kwsutter@gmail.com]
>> Sent: Friday, 5 October 2007 9:01 a.m.
>> To: dev@openjpa.apache.org
>> Subject: Cloning Calendar proxies
>>
>> Hi,
>> It seems that the IBM JDK is cloning a Calendar object when
>performing
>> the
>> .equals() method. If I call .equals() on one of our Calendar proxy
>> objects, the underlying implementation seems to be cloning
>the object
>> before determining the equality. While using this cloned
>object, one
>> of the setter methods is called. Since this is a cloned Calendar
>> proxy, we do some processing to access the associated StateManager.
>> But, that requires access to a Broker and there is no Broker
>instance
>> associated with this cloned object and we end up throwing an
>> IllegalStateException. Due to that exception, the .equals() always
>> returns false.
>>
>> So, before I start experimenting with various fix strategies, I'm
>> looking for some guidance from the original developers...
>>
>> o Should we override the clone() method? And, if we do,
>should we be
>> returning a non-proxy version of a Calendar object? Or, should we
>> ensure that a fully populated Calendar proxy object get returned?
>>
>> o Or, should we think about overriding the .equals method on the
>> Calendar proxies? I'm not too thrilled with this since then
>we'll be
>> attempting to implement the javadoc for these object types.
>>
>> Whatever we determine will probably apply to all of our proxy object
>> types, even though we're only hitting this problem with the Calendar
>> proxy due to the IBM JDK.
>>
>> Thoughts or suggestions?
>> Kevin
>>
>
>
Notice: This email message, together with any attachments, may contain information of BEA Systems, Inc., its subsidiaries and affiliated entities, that may be confidential, proprietary, copyrighted and/or legally privileged, and is intended solely for the use of the individual or entity named in this message. If you are not the intended recipient, and have received this message in error, please immediately return this by email and then delete it.
RE: Cloning Calendar proxies
Posted by Evan Ireland <ei...@sybase.com>.
Just curious, why are Calendar objects being proxied in the
first place?
> -----Original Message-----
> From: Kevin Sutter [mailto:kwsutter@gmail.com]
> Sent: Friday, 5 October 2007 9:01 a.m.
> To: dev@openjpa.apache.org
> Subject: Cloning Calendar proxies
>
> Hi,
> It seems that the IBM JDK is cloning a Calendar object when
> performing the
> .equals() method. If I call .equals() on one of our Calendar
> proxy objects, the underlying implementation seems to be
> cloning the object before determining the equality. While
> using this cloned object, one of the setter methods is
> called. Since this is a cloned Calendar proxy, we do some
> processing to access the associated StateManager. But, that
> requires access to a Broker and there is no Broker instance
> associated with this cloned object and we end up throwing an
> IllegalStateException. Due to that exception, the .equals()
> always returns false.
>
> So, before I start experimenting with various fix strategies,
> I'm looking for some guidance from the original developers...
>
> o Should we override the clone() method? And, if we do,
> should we be returning a non-proxy version of a Calendar
> object? Or, should we ensure that a fully populated Calendar
> proxy object get returned?
>
> o Or, should we think about overriding the .equals method on
> the Calendar proxies? I'm not too thrilled with this since
> then we'll be attempting to implement the javadoc for these
> object types.
>
> Whatever we determine will probably apply to all of our proxy
> object types, even though we're only hitting this problem
> with the Calendar proxy due to the IBM JDK.
>
> Thoughts or suggestions?
> Kevin
>
Re: Cloning Calendar proxies
Posted by Kevin Sutter <kw...@gmail.com>.
Hi Craig,
On 10/4/07, Craig L Russell <Cr...@sun.com> wrote:
>
> Hi Kevin,
>
> On Oct 4, 2007, at 1:00 PM, Kevin Sutter wrote:
>
> > Hi,
> > It seems that the IBM JDK is cloning a Calendar object when
> > performing the
> > .equals() method.
>
> Why is that?
:-) Who knows? I'm not privy to the IBM JDK implementation or why they do
what they do...
> If I call .equals() on one of our Calendar proxy objects,
> > the underlying implementation seems to be cloning the object before
> > determining the equality. While using this cloned object, one of
> > the setter
> > methods is called. Since this is a cloned Calendar proxy, we do some
> > processing to access the associated StateManager.
>
> Seems like the clone should be treated as detached, which implies
> that we implement our own clone() method, something like: load fields
> from database; super.clone(); StateManager = null; return;
I would agree with this approach, but I wanted to get some other opinions
before going down this path. This would resolve the issue that we're
experiencing as well...
> But, that requires access
> > to a Broker and there is no Broker instance associated with this
> > cloned
> > object and we end up throwing an IllegalStateException. Due to that
> > exception, the .equals() always returns false.
> >
> > So, before I start experimenting with various fix strategies, I'm
> > looking
> > for some guidance from the original developers...
> >
> > o Should we override the clone() method? And, if we do, should we be
> > returning a non-proxy version of a Calendar object? Or, should we
> > ensure
> > that a fully populated Calendar proxy object get returned?
>
> I'm not clear what you mean by "fully populated Calendar". Do you
> mean simply instantiated with values from the database? If so, yes.
By "fully populated", I meant attempt to make the StateManager usable.
Basically, do a deep copy for the clone. But, I like the approach you
mentioned in your earlier comment and just transfer the state of the object,
but null out the StateManager. This would prevent the access to the Broker
and we'd be happy.
>
> > o Or, should we think about overriding the .equals method on the
> > Calendar
> > proxies? I'm not too thrilled with this since then we'll be
> > attempting to
> > implement the javadoc for these object types.
>
> Oh oh. Please no.
:-) Just thought I would throw that idea out there.
Thanks,
Kevin
Craig
> >
> > Whatever we determine will probably apply to all of our proxy
> > object types,
> > even though we're only hitting this problem with the Calendar proxy
> > due to
> > the IBM JDK.
> >
> > Thoughts or suggestions?
> > Kevin
>
> Craig Russell
> Architect, Sun Java Enterprise System http://java.sun.com/products/jdo
> 408 276-5638 mailto:Craig.Russell@sun.com
> P.S. A good JDO? O, Gasp!
>
>
>
Re: Cloning Calendar proxies
Posted by Craig L Russell <Cr...@Sun.COM>.
Hi Kevin,
On Oct 4, 2007, at 1:00 PM, Kevin Sutter wrote:
> Hi,
> It seems that the IBM JDK is cloning a Calendar object when
> performing the
> .equals() method.
Why is that?
> If I call .equals() on one of our Calendar proxy objects,
> the underlying implementation seems to be cloning the object before
> determining the equality. While using this cloned object, one of
> the setter
> methods is called. Since this is a cloned Calendar proxy, we do some
> processing to access the associated StateManager.
Seems like the clone should be treated as detached, which implies
that we implement our own clone() method, something like: load fields
from database; super.clone(); StateManager = null; return;
> But, that requires access
> to a Broker and there is no Broker instance associated with this
> cloned
> object and we end up throwing an IllegalStateException. Due to that
> exception, the .equals() always returns false.
>
> So, before I start experimenting with various fix strategies, I'm
> looking
> for some guidance from the original developers...
>
> o Should we override the clone() method? And, if we do, should we be
> returning a non-proxy version of a Calendar object? Or, should we
> ensure
> that a fully populated Calendar proxy object get returned?
I'm not clear what you mean by "fully populated Calendar". Do you
mean simply instantiated with values from the database? If so, yes.
>
> o Or, should we think about overriding the .equals method on the
> Calendar
> proxies? I'm not too thrilled with this since then we'll be
> attempting to
> implement the javadoc for these object types.
Oh oh. Please no.
Craig
>
> Whatever we determine will probably apply to all of our proxy
> object types,
> even though we're only hitting this problem with the Calendar proxy
> due to
> the IBM JDK.
>
> Thoughts or suggestions?
> Kevin
Craig Russell
Architect, Sun Java Enterprise System http://java.sun.com/products/jdo
408 276-5638 mailto:Craig.Russell@sun.com
P.S. A good JDO? O, Gasp!