@Override
	public int insertEntity(String entitySet, String entityPK, HashMap<String, ByteIterator> values, boolean insertImage) {

		session = sessionFactory.openSession();


		try{
			tx = session.beginTransaction();
			Class insertClass = Class.forName("postgreHibernateClient."+entitySet.toUpperCase());
			Constructor constructor = insertClass.getConstructor(new Class[]{});

			
			//GET ALL SETTER METHODS FOR THE TABLE entityset
			Map<String, Method> methods = FactoryInsert.getSetterMethods(insertClass);
			Object insertInstance = constructor.newInstance();
			
			if(entitySet.equalsIgnoreCase("users"))
				values.put("userid", new ObjectByteIterator(entityPK.getBytes()));
			else if(entitySet.equalsIgnoreCase("resources"))
				values.put("rid", new ObjectByteIterator(entityPK.getBytes()));
				
			Iterator<String> i = values.keySet().iterator();
			//System.out.print(values.size());
			while( i.hasNext()){
				String s= i.next();
				Method m = methods.get(s);
				if(insertImage && (s.equalsIgnoreCase("pic") || s.equalsIgnoreCase("tpic"))){
						m.invoke(insertInstance, ((ObjectByteIterator)values.get(s)).toArray());
						continue;
				}
				m.invoke(insertInstance, values.get(s).toString());
			}
			session.save(insertInstance);
			
			if(entitySet.equalsIgnoreCase("resources")){
				USERS u = new USERS();
				u = (USERS) session.get(USERS.class, values.get("creatorid").toString());
				u.setResCnt(u.getResCnt()+1);
				session.save(u);
			}
			
			load_index++;
			if(load_index%50==0){
				System.out.println("loading "+ entitySet );
				session.flush();
				session.clear();
			}
			tx.commit();
		}
		catch (Exception e) {
			tx.rollback();
			System.out.println("errrrrrrrrrrror"+e.getMessage()+"   ");
			e.printStackTrace();
		} 
		finally {
			session.close();
		}
		
		return 0;
	}