I am trying to implement Hazelcast in a simple web application.
I am trying to store a custom object into my Hazelcast Map and have implemented Serializable in my Bid Object Class with the necessary imports.
import java.io.Serializable;
Here is a snippet of the class object.
public class Bid implements Serializable{
private String bidId;
private String stock;
private int price;
private String userId;
private Date date;
Here are the syntax as with the tutorial to store the Bid Object into the Map where newBid is a Bid Object.
Config cfg = new Config();
HazelcastInstance instance = Hazelcast.newHazelcastInstance(cfg);
Map<String, Bid> mapBids = instance.getMap("bids");
mapBids.put(newBid.getUserId(), newBid);
My Hazelcast nodes are up and running but when I query the bids map, I get the following error.
com.hazelcast.nio.serialization.HazelcastSerializationException: java.lang.Class
NotFoundException: aa.Bid
at com.hazelcast.nio.serialization.DefaultSerializers$ObjectSerializer.r
ead(DefaultSerializers.java:190)
at com.hazelcast.nio.serialization.StreamSerializerAdapter.read(StreamSe
rializerAdapter.java:59)
at com.hazelcast.nio.serialization.SerializationServiceImpl.toObject(Ser
ializationServiceImpl.java:221)
at com.hazelcast.spi.impl.NodeEngineImpl.toObject(NodeEngineImpl.java:15
6)
at com.hazelcast.map.MapService.toObject(MapService.java:773)
at com.hazelcast.map.proxy.MapProxyImpl.entrySet(MapProxyImpl.java:502)
at com.hazelcast.examples.TestApp.handleMapEntries(TestApp.java:882)
at com.hazelcast.examples.TestApp.handleCommand(TestApp.java:371)
at com.hazelcast.examples.TestApp.start(TestApp.java:187)
at com.hazelcast.examples.TestApp.main(TestApp.java:1641)
Caused by: java.lang.ClassNotFoundException: aa.Bid
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at com.hazelcast.nio.ClassLoaderUtil.loadClass(ClassLoaderUtil.java:109)
at com.hazelcast.nio.IOUtil$1.resolveClass(IOUtil.java:89)
at java.io.ObjectInputStream.readNonProxyDesc(Unknown Source)
at java.io.ObjectInputStream.readClassDesc(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
at com.hazelcast.nio.serialization.DefaultSerializers$ObjectSerializer.r
ead(DefaultSerializers.java:185)
... 9 more
The object class is located in the same folder as my web app with the necessary import syntax but it is not reading it. I have added the CLASSPATH to my Hazelcast jar file as well.
Are there any variable that I have to make Transient in my Bid class object in order for Serializable to work? Or am I missing something?