title: Hazelcast: Does Portable Serialization needs objects to be shared between client and server?
body: <p>I am getting the below exception:</p>
  
  <blockquote>
    <p>Could not find PortableFactory for factory-id: 1
    com.hazelcast.nio.serialization.HazelcastSerializationException: Could
    not find PortableFactory for factory-id: 1</p>
  </blockquote>
  
  <p>On the client side I have the following code:</p>
  
  <pre><code>public class ClientTest {
  
      public static void main(String[] args) {
  
          List&lt;String&gt; nodes = new ArrayList&lt;String&gt;();
          nodes.add("localhost:5701");
  
          ClientConfig clientConfig = new ClientConfig();
          ClientNetworkConfig networkConfig = new ClientNetworkConfig();
          networkConfig.setAddresses(nodes);
          clientConfig.setNetworkConfig(networkConfig);
  
          SerializationConfig serCong = clientConfig.getSerializationConfig();
          serCong.addPortableFactory(1, new UserFactoryImpl());
          serCong.setPortableVersion(1);
  
          HazelcastInstance hzClient1 = HazelcastClient.newHazelcastClient(clientConfig);
  
          IMap&lt;String, User&gt; map = hzClient1.getMap("user");
          System.out.println(map.size() + "hiten");
          User user1 = new User();
          user1.setFirstName("hiten");
          user1.setLastName("singh");
          map.put("1", user1);
  
  
          //hz1.getLifecycleService().terminate();
          System.out.println(map.size() + "after");
  
          User user2 = new User();
          user2.setFirstName("hiten1");
          user2.setLastName("singh1");
          map.put("2", user2);
  
          UserEntryProcessor entryProc = new UserEntryProcessor();
          User userRes = (User)map.executeOnKey("1", entryProc);
      }
  
      static class UserEntryProcessor implements EntryProcessor&lt;String, User&gt;, HazelcastInstanceAware {
  
          private transient HazelcastInstance hazelcastInstance;
  
          @Override
          public Object process(Entry&lt;String, User&gt; entry) {
              User user = entry.getValue();
              if(user != null) {
                  System.out.println(user.getFirstName());
              }
  
              return user;
          }
  
          @Override
          public EntryBackupProcessor&lt;String, User&gt; getBackupProcessor() {
              return null;
          }
  
          @Override
          public void setHazelcastInstance(HazelcastInstance hazelcastInstance) {
              this.hazelcastInstance = hazelcastInstance;
          }
  
      }
  
      static class UserFactoryImpl implements PortableFactory{
  
          public final static int USER_PORTABLE_ID = 1;
  
          public final static int FACTORY_ID = 1;
  
          public Portable create(int classId) {
              switch (classId) {
                  case USER_PORTABLE_ID:
                      return new User();
              }
              return null;
          }
      }
  
      static class User implements Portable {
  
          private String firstName;
          private String lastName;
  
          public String getLastName() {
              return lastName;
          }
  
          public void setLastName(String lastName) {
              this.lastName = lastName;
          }
  
          public String getFirstName() {
              return firstName;
          }
  
          public void setFirstName(String firstName) {
              this.firstName = firstName;
          }
  
          @Override
          public int getFactoryId() {
              return UserFactoryImpl.FACTORY_ID;
          }
  
          @Override
          public int getClassId() {
              return UserFactoryImpl.USER_PORTABLE_ID;
          }
  
          @Override
          public void writePortable(PortableWriter writer) throws IOException {
              writer.writeUTF("first_name", firstName);
              writer.writeUTF("last_name", lastName);
          }
  
          @Override
          public void readPortable(PortableReader reader) throws IOException {
              firstName = reader.readUTF("first_name");
              lastName = reader.readUTF("last_name");
          }
      }
  }
  </code></pre>