dpHibernate and Oracle ClassCastException

18 views
Skip to first unread message

Fahrettin

unread,
Jan 20, 2011, 4:34:22 AM1/20/11
to dpHibernate
1.I am working on lazyLoadingWithSpring example, I use 2.0.3 RC-3 jars
and dpHibernate-2.0-RC3.swc.(But I have to compile the flex-src files
with flex sdk 3.5 ). Our database is Oracle 10g 10.2.0.4 . If I change
the Id type in BaseEntity.java from Integer to Long I get an error at
Flex side. It says:
Fault when loading data: java.lang.ClassCastException :
java.lang.String cannot be cast to java.lang.Long
but When I change to data type of Id field in BaseEntity.java to
String it works, no error.

2. I tried the same example in mySQL database, with the same
configuration. If the Id datatype is Integer I got no Error. But when
I change it to Long, the error message is as fallows.
Fault when loading data: java.lang.ClassCastException :
java.lang.Integer cannot be cast to java.lang.Long

3. I am not sure which side is cousing the error. It seems to me that
Flex side is sending id as String, Because I can reach the proxy Key,
and see that proxyInitialized value is set to false from flex side.

dae

unread,
Jan 21, 2011, 8:03:51 PM1/21/11
to dpHibernate
I'm seeing similar behavior. I have a domain class called Contact
with identity of type Long. When a List<Contact> object is passed to
the flex client, only the first row has real data. The others rows
show NaN.

Here's the exception on the java side:
NullableType - could not bind value '2' to parameter: 1;
java.lang.Integer cannot be cast to java.lang.Long

When I change the Contact identity type to Integer, everything works
fine.

On Jan 20, 1:34 am, Fahrettin <fahrettin.akb...@gmail.com> wrote:
> 1.I am working on lazyLoadingWithSpring example, I use 2.0.3 RC-3 jars
> and dpHibernate-2.0-RC3.swc.(But I have to  compile the flex-src files
> with flex sdk 3.5 ). Our database is Oracle 10g 10.2.0.4 . If I change
> the Id type in BaseEntity.java from Integer toLongI get an error at
> Flex side. It says:
> Fault when loading data: java.lang.ClassCastException :
> java.lang.String cannot be cast to java.lang.Long
> but When I change to data type of Id field in BaseEntity.java to
> String it works, no error.
>
> 2. I tried the same example in mySQL database, with the same
> configuration. If the Id datatype is Integer I got no Error. But when
> I change it toLong, the error message is as fallows.

Umut

unread,
Feb 7, 2011, 1:00:05 AM2/7/11
to dpHibernate
Hi, we are working with Fahrettin and after some digging into the
framework we figured out how this problem occurs and used a
workaround. Sharing it with you so any other poor soul out there
looking for an answer to this problem might save the torture.

Here it goes:

The problem with java.lang.Long is on the flex side this type
corresponds to Number, which is also used for any fractional number
(i.e double or float) long integer as in Long. Also it might sometimes
be interpreted as int.

As I understand it, Number can be interpreted as integer or double
when it arrives to server depending on its value. For example if you
have an object with proxyKey value 1, it will be interpreted as
Integer on the server even though you defined proxyKey as Long(on
server). On the other hand if you have a 17 digit number as your
proxyKey it probably will be interpreted as Double when it arrives to
server. (I actually never seen it interpreted as Long it either gets
Integer or Double I think)

The problem roots from nature of type Number in Action Script.

How can the problem be solved then? Well it depends...

If you have mixed id types (i.e. Integer and Long) then you are in
trouble since there is no way of knowing which type it is when it
arrives to server. But if you have only Long id's as we do, you can
change a few places in the dpHibernate code (doing something like new
Long (incomingProxyKey + "")) and make it work for you. But with this
workaround you will make the framework incompatible with any id types
other than Long.

Although I think it is the shortcoming of action script in my opinion
(not having a seperate type for Long) to make dpHibernate work with
all types as id's, I see no other way than to send another field that
contains the type of id as part of proxy information saying "this is
supposed to be java.lang.Integer" or "this is supposed to be
java.lang.Long".

I hope it helps. And thanks to the dpHibernate team for the
framework :)

Umut

dae

unread,
Feb 12, 2011, 3:26:08 PM2/12/11
to dpHibernate
There's a patch for this in the Updates section of Project Home. Look
for r238.

Dae
Reply all
Reply to author
Forward
0 new messages