map - Hazelcast IMap.get() throws HazelcastSerializationException, but IMap.put() works fine -
I have a Hazelcast server example running on a VJ. Data can be found in the I connect to this server with a client instance and try to add an object to that map: The upper code gives me the following console output: What's the problem here? Why can not I just put it in the map? Here are the exception details: Stacktrace seems to be that there is no default constructor in your class (constructor without parameters). If you have defined a constructor with parameters, then the default constructor is not automatically created by the compiler and you have to define it clearly. Alternatively your class or constructor can not be public but package-private or private. MAP < Integer, User & gt; is considered to be stored in, where the user class occurs as follows:
Public class user tools com.hazelcast.nio Serialization.DataSerializable {Private Integer ID; The name of the private string; Private string Nick; Private boolean sex; // Miller & amp; Amp; Setters @ Override Public Virus ListData (Object Data Out) throws IOException {out.writeInt (id.intValue ()); Out.writeUTF (name); Out.writeUTF (Nick); Out.writeBoolean (sex); } @ Override throws Public Wide Reddata (ObjectDetinput) IOException {id = (integer) in.readInt (); Name = in.readUTF (); Nick = in. Rottief (); Sex = in.readBoolean (); }
System.out.println ("Map size:" + Map.size ()); map.put (1, user); System.out.println ("map size:" + map.size ()); System.out.println (map.containsKey (1)? "Yes": "no"); System.out.println (map.containsValue (user)? "Yes": "no"); User asks = (user) map.get (1); / * This line is 64 * / System.out.println (queried.toString ());
Map size: 0 Map size: 1 Yes Yes < P> And the following exception to the line:
User Inquiry = (user) map.get (1); :
Data Serial Alert, Problems while Reading Namespace: 0, id: 0, Category: com.blabla.User, Exception: com.blabla.User. & Lt; Init & gt; ()
com.hazelcast.nio.serialization.DataSerializer.read (DataSerializer.java.114) com.hazelcast.nio.serialization.DataSerializer Read (DataSerializer.java36) com.hazelcast.nio.serialization.StreamSerializerAdapter.read (StreamSerializerAdapter.java59) com.hazelcast.nio.serialization SerializationServiceImpl.toObject (SerializationServiceImpl.java Month 18) com.hazelcast.client.spi.impl.ClientClusterServiceImpl ._sendAndReceive (ClientClusterServiceImpl.java:172) com.hazelcast.client.spi.impl.ClientClusterServiceImpl.sendAndReceive (ClientClusterServiceImpl.java:137) Com.hazelcast.client.spi.impl.ClientInvocationServiceImpl.invokeOnTarget (ClientInvocationServiceImpl.java 42) com. hazelcast.client.spi.impl.ClientInvocationServiceImpl.invokeOnKeyOwner (Client Invocation System.Java: 53) com.hazelcast.client.proxy.ClientMapProxy Say Do not (ClientMapProxy.java:492) com.hazelcast.client.proxy.ClientMapProxy Find (ClientMapProxy.java:83) com.blabla.HazelcastFactory.insertUser (HazelcastFactory.java:64) java.lang.NoSuchMethodException:. Com.dileky.User & LT; Init & gt; () Java.lang.Class.getConstructor0 (class. Java: 2800) java.lang.Class.getDeclaredConstructor (Class.java:2043) com.hazelcast.nio.ClassLoaderUtil.newInstance (ClassLoaderUtil.java:54) com.hazelcast. Niokclasslotderutilkneinstans (Classlotderutilkjawa:50) Comkhelkastknioksserializtionkdtsserializerkreed (Dtsserializerkjawa:l03) Comkhelkastknioksserializtionkdtsserializerkreed (Dtsserializerkjawa:36) com. Hazelcast.nio.serialization.StreamSerializerAdapter.read (StreamSerializerAdapter. Java: 59) com.hazelcast.nio.serialization.SerializationServiceImpl.toObject (SerializationServiceImpl.java:218) com.hazelcast.client.spi.impl.ClientClusterServiceImpl._sendAndReceive (ClientClusterServiceImpl. Java: 172) com.hazelcast.client.spi Impl.ClientClusterServiceImpl.sendAndReceive (ClientClusterServiceImpl.java:137) com.hazelcast.client.spi.impl.ClientI nvocationServiceImpl.invokeOnTarget (ClientInvocationServiceImpl.java 42) com.hazelcast.client.spi.impl.ClientInvocationServiceImpl.invokeOnKeyOwner (Client Invocation System Implements JavaWire) com.hazelcast.client.proxy.ClientMapProxy.invoke (ClientMapProxy.java:492) com. hazelcast.client.proxy.ClientMapProxy.get (ClientMapProxy.java:83) com.blabla.HazelcastFactory.insertUser (HazelcastFactory.java:64)
public class user {// field public user () {} // gate / sets}}
Comments
Post a Comment