• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Is a hashmap containing non-serialised object throws RemoteException?

 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am having an object , say Employee. Inside this object I have an attribute of type Hashmap.

I am using this Employee object for passing as parameter to EJB method xxxx(). The return type of method xxx() is also the Emplyee object.

But in EJB, in method xxxx(), if I put a non-serializable object inside the hasmap of Emplyee & tried to return that Employee object , then I get an RemoteException saying non-serilizable object.

If I put an empty hashmap in object Emplyee & then returns it, it works fine.

Is there any clue, why this is happing?

I am using RAD & portal server V5.1.
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Is there any clue, why this is happing?


Yes. The reason is this:


...if I put a non-serializable object inside the hasmap of Emplyee & tried to return that Employee object...



HashMap is serializable, so it is an object you can use in a distributed environment. Your Employee object is not, so you can't use it a distributed environment.
[ August 09, 2006: Message edited by: Paul Sturrock ]
 
prasad kulkarni
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hey just wait........Employee is also serializable........
The structure is like this :

class Employee implements serializable{
........
........
private HashMap myMap = null;
........
........
}

When I return an object of Emplyoee with myMap containg an non-serialized object , there is RemoteException & when I return an object of Emplyoee with myMap as "new HashMap" or as "null", it works fine ?
Now tell me is there any clue?
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry your post wasn'r clear, I read it as the Employee class not being serializable, rather than your employee class having a property of the type HashMap into which you are putting non-serializable objects. So:


When I return an object of Emplyoee with myMap containg an non-serialized object , there is RemoteException


Yes there would be. If an object can't be serialized, it can't be passed over a network or between JVMs, so no EJB method can return any objects that are not serializable. If you just return an empty HashMap (which is a serializable object) there is no problem. If you start putting non-serializable objects in the HashMap, you create a problem. Reading the JavaDocs for the Serializable interface, they state:


When traversing a graph, an object may be encountered that does not support the Serializable interface. In this case the NotSerializableException will be thrown and will identify the class of the non-serializable object.

 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic