RE: ClassCastException in pcReplaceField

2010-01-25 Thread Udi

Hey Russel,
 I just added the Comparable implementation, and I hope this will solve the
problem.

Thanks,
Udi
-- 
View this message in context: 
http://n2.nabble.com/ClassCastException-in-pcReplaceField-tp4392185p4459284.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.


RE: ClassCastException in pcReplaceField

2010-01-22 Thread Russell Collins
Honestly, you are probably correct in that all you need is a hashCode and 
equals for a Set.  I guess the real question is, what implementation of Set is 
being returned by OpenJPA?  If it is a TreeSet (most common), then we are on 
the same page since TreeSet is an implementation of an ordered collection with 
the following hierarchy.

Set - SortedSet - NavigableSet - TreeSet

I guess I am saying that you would need to use Comparable because I have not 
used any of the other implementations and TreeSet is the most common.

-Original Message-
From: craig.russ...@sun.com [mailto:craig.russ...@sun.com]
Sent: Thursday, January 21, 2010 9:45 PM
To: users@openjpa.apache.org
Subject: Re: ClassCastException in pcReplaceField

Hi,

On Jan 21, 2010, at 7:23 PM, Russell Collins wrote:

 While the initial thought is that the equals() method would work,
 the specification for Set requires a compareTo method be present by
 implementing the Comparable interface.

This is not my understanding. Set requires only hashCode and equals.
Ordered collections (e.g. TreeSet) require the elements to implement
Comparable or to have a Comparator specified at creation.

Maybe we're reading different parts of the spec...

Craig

Craig L Russell
Architect, Sun Java Enterprise System http://db.apache.org/jdo
408 276-5638 mailto:craig.russ...@sun.com
P.S. A good JDO? O, Gasp!


CONFIDENTIALITY NOTICE: The information contained in this electronic mail 
(email) transmission (including attachments), is intended by MCLANE ADVANCED 
TECHNOLOGIES for the use of the named individual or entity to which it is 
addressed and may contain information that is privileged, confidential and/or 
protected as a trade secret. It is not intended for transmission to, or receipt 
by, any individual or entity other than the named addressee(s). If you have 
received this email in error, please delete it (including attachments) and any 
copies thereof without printing, copying or forwarding it, and notify the 
sender of the error by email reply immediately.


Re: ClassCastException in pcReplaceField

2010-01-21 Thread Craig L Russell

Hi,

On Jan 21, 2010, at 7:23 PM, Russell Collins wrote:

While the initial thought is that the equals() method would work,  
the specification for Set requires a compareTo method be present by  
implementing the Comparable interface.


This is not my understanding. Set requires only hashCode and equals.  
Ordered collections (e.g. TreeSet) require the elements to implement  
Comparable or to have a Comparator specified at creation.


Maybe we're reading different parts of the spec...

Craig

Craig L Russell
Architect, Sun Java Enterprise System http://db.apache.org/jdo
408 276-5638 mailto:craig.russ...@sun.com
P.S. A good JDO? O, Gasp!



RE: ClassCastException in pcReplaceField

2010-01-19 Thread Russell Collins
Based on the code that has been provided I am making the assumption that you 
are mapping your OneToMany to a Set collection.  If this is the case, a Set 
collection will not allow duplicates.  In order to check for duplicates, an 
object that is getting placed in the Set needs to show how it is unique.  
Therefore the objects that are going into the Set collection need to implement 
the Comparable (Sorry about IComparable) interface to be inserted.  In this 
case, you would need object B to implement the Comparable interface.  You would 
not need object A to implement Comparable as the comparisons are done on the 
instances of object B.  If you are still getting cast errors, then it is 
probably something else.  You could also try changing the Set collection type 
to a List to see if you get this error and you would not need to implement the 
Comparable interface.  Remember that a List collection can contain duplicates.

-Original Message-
From: Udi [mailto:saba...@gmail.com]
Sent: Sunday, January 17, 2010 1:07 AM
To: users@openjpa.apache.org
Subject: RE: ClassCastException in pcReplaceField


P.S. - I forgot to mention that I'm enhanching at runtime using javaagent.
--
View this message in context: 
http://n2.nabble.com/ClassCastException-in-pcReplaceField-tp4392185p4407523.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

CONFIDENTIALITY NOTICE: The information contained in this electronic mail 
(email) transmission (including attachments), is intended by MCLANE ADVANCED 
TECHNOLOGIES for the use of the named individual or entity to which it is 
addressed and may contain information that is privileged, confidential and/or 
protected as a trade secret. It is not intended for transmission to, or receipt 
by, any individual or entity other than the named addressee(s). If you have 
received this email in error, please delete it (including attachments) and any 
copies thereof without printing, copying or forwarding it, and notify the 
sender of the error by email reply immediately.


RE: ClassCastException in pcReplaceField

2010-01-16 Thread Udi

Hey Russell,
Thanks for the reply.
I don't think I understand what you offered. (By IComparable - I assume you
meant simply Comparable) 
A and B are not comparable objects. They are entirely different object, and
that is why it's so strange...
I'm posting the stack trace in a few moments..


Russell Collins wrote:
 
 It looks like you are trying to add items to a Set.  You will get these
 casting exceptions if your classes do not implement the IComparable
 interface.  If they do implement the interface, then it is another issue.
 

-- 
View this message in context: 
http://n2.nabble.com/ClassCastException-in-pcReplaceField-tp4392185p4407472.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.


RE: ClassCastException in pcReplaceField

2010-01-16 Thread Udi

http://n2.nabble.com/file/n4407518/2.pdf 2.pdf 

That's the stack trace.
mypackage, A and B is my stuff.
Hope this can be of more use...
Thanks,
Udi
-- 
View this message in context: 
http://n2.nabble.com/ClassCastException-in-pcReplaceField-tp4392185p4407518.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.


RE: ClassCastException in pcReplaceField

2010-01-16 Thread Udi

P.S. - I forgot to mention that I'm enhanching at runtime using javaagent.
-- 
View this message in context: 
http://n2.nabble.com/ClassCastException-in-pcReplaceField-tp4392185p4407523.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.


RE: ClassCastException in pcReplaceField

2010-01-15 Thread Russell Collins
It looks like you are trying to add items to a Set.  You will get these casting 
exceptions if your classes do not implement the IComparable interface.  If they 
do implement the interface, then it is another issue.

-Original Message-
From: Rick Curtis [mailto:curti...@gmail.com]
Sent: Thursday, January 14, 2010 5:02 PM
To: users@openjpa.apache.org
Subject: Re: ClassCastException in pcReplaceField

Udi -

You're really going to need to post more information than this for anyone to
figure out what is going on I understand you don't want to post your
application call stack, what about posting a filtered call stack? That might
be a good starting point.

You say you are enhancing your entities at runtime... is that via the
-javaagent or are you using the subclassing support?

--
Thanks,
Rick

On Thu, Jan 14, 2010 at 6:23 AM, Udi saba...@gmail.com wrote:


 Hey, first of all, I'm sorry for not pasting the stack - I just can't.
 I'm using OpenJPA 1.2.0
 I have 2 classes:
 class A{
 @OneToMany(mappedBy=a)
 Set
 }
 class B{
 @ManyToOne
 A a;
 }

 Now, at some point (I can't create a consistent testcase..) I get
 ClassCastException: B cannot be cast to A.
 The stack (typed, so sorry once again...):
 B.pcReplaceField()
 StateManagerImpl.replaceField()
 StateManagerImpl.storeObjectField()
 StateManagerImpl.storeObject()
 RelationFieldStrategy.load()
 FieldMapping.load()
 JDBCStoreManager.load()

 I'm enhancing entities at runtime, so I used decompiler to see the
 generated
 class, and in the problematic line it appears like a cast for a field.

 Anyone knows how can it happen (and even more interesting - how to solve
 the
 problem? :) )

 Thanks,
 Udi
 --
 View this message in context:
 http://n2.nabble.com/ClassCastException-in-pcReplaceField-tp4392185p4392185.html
 Sent from the OpenJPA Users mailing list archive at Nabble.com.


CONFIDENTIALITY NOTICE: The information contained in this electronic mail 
(email) transmission (including attachments), is intended by MCLANE ADVANCED 
TECHNOLOGIES for the use of the named individual or entity to which it is 
addressed and may contain information that is privileged, confidential and/or 
protected as a trade secret. It is not intended for transmission to, or receipt 
by, any individual or entity other than the named addressee(s). If you have 
received this email in error, please delete it (including attachments) and any 
copies thereof without printing, copying or forwarding it, and notify the 
sender of the error by email reply immediately.


Re: ClassCastException in pcReplaceField

2010-01-14 Thread Rick Curtis
Udi -

You're really going to need to post more information than this for anyone to
figure out what is going on I understand you don't want to post your
application call stack, what about posting a filtered call stack? That might
be a good starting point.

You say you are enhancing your entities at runtime... is that via the
-javaagent or are you using the subclassing support?

-- 
Thanks,
Rick

On Thu, Jan 14, 2010 at 6:23 AM, Udi saba...@gmail.com wrote:


 Hey, first of all, I'm sorry for not pasting the stack - I just can't.
 I'm using OpenJPA 1.2.0
 I have 2 classes:
 class A{
 @OneToMany(mappedBy=a)
 Set
 }
 class B{
 @ManyToOne
 A a;
 }

 Now, at some point (I can't create a consistent testcase..) I get
 ClassCastException: B cannot be cast to A.
 The stack (typed, so sorry once again...):
 B.pcReplaceField()
 StateManagerImpl.replaceField()
 StateManagerImpl.storeObjectField()
 StateManagerImpl.storeObject()
 RelationFieldStrategy.load()
 FieldMapping.load()
 JDBCStoreManager.load()

 I'm enhancing entities at runtime, so I used decompiler to see the
 generated
 class, and in the problematic line it appears like a cast for a field.

 Anyone knows how can it happen (and even more interesting - how to solve
 the
 problem? :) )

 Thanks,
 Udi
 --
 View this message in context:
 http://n2.nabble.com/ClassCastException-in-pcReplaceField-tp4392185p4392185.html
 Sent from the OpenJPA Users mailing list archive at Nabble.com.