mnimer / dphibernate

Automatically exported from code.google.com/p/dphibernate
0 stars 0 forks source link

Java entity with property of type Set : "java.lang.IllegalArgumentException: argument type mismatch" #24

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

1. Having a Java entity class with a property of type java.util.Set (with
java.util.List it works fine)
Example:
public class Cart extends HibernateProxy implements Serializable  {
 private Set items = new HashSet(0);
}

2. In your flex application, call a service method which take this entity
as a parameter.
Example:
srv.createCart(new Cart());

What is the expected output? What do you see instead?

The Cart Object (and particularly the items property) is not well
deserialized and dpHibernate throws this exception:
java.lang.IllegalArgumentException: argument type mismatch
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.jav
a:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at
net.digitalprimates.persistence.translators.hibernate.HibernateDeserializer.read
Bean(HibernateDeserializer.java:214)
...

What version of the product are you using? On what operating system?
Spring 2.5, Hibernate 3.2, Ubuntu operating system

Please provide any additional information below.

I think the problem comes from the "readCollection" method of the
"HibernateDeserializer" class.
During the deserialization process, the property of type Set is processed
by the "readCollection" method (because the Set type is also of type
Collection).
In this method the property is transformed into an ArrayList which then
cause an error of "IllegalArgumentException" when the method try to cast
the translated property of type ArrayList in a Map type.

I resolved the problem by modifying the "readCollection" method like that:

for (Object o : (Collection) obj)
{
 o = translate(o, type);
}
return obj;

Like this, the type of the property (of type Collection) is not changed and
the error don't occurred !

Hope this could help.
Bye.

Original issue reported on code.google.com by arnoux.f...@gmail.com on 2 Dec 2008 at 12:23

GoogleCodeExporter commented 9 years ago

Original comment by martypit...@gtempaccount.com on 15 Mar 2011 at 3:21