I have a strange issue, using Ignite 1.2

I have set up a JDBC backed cache, loading the cache works fine, I even can see 
that its setting the appropriate values for my test object, however when I try 
to get the object out for the specified key it gives me back nothing, however 
if I iterate over the entry list, the key in the cache is not null but the 
value is null.

##object in question


/**
 * UuidTest definition.
 *
 * Code generated by Apache Ignite Schema Import utility: 06/26/2015.
 */
public class UuidTest implements Serializable {
    /** */
    private static final long serialVersionUID = 0L;

    /** Value for myid. */
    private Object myid;

    /** Value for md5hash. */
    private String md5hash;

    /**
     * Empty constructor.
     */
    public UuidTest() {
        // No-op.
    }

    /**
     * Full constructor.
     */
    public UuidTest(
        Object myid,
        String md5hash
    ) {
        this.myid = myid;
        this.md5hash = md5hash;
    }

    /**
     * Gets myid.
     *
     * @return Value for myid.
     */
    public Object getMyid() {
        return myid;
    }

    /**
     * Sets myid.
     *
     * @param myid New value for myid.
     */
    public void setMyid(Object myid) {

        System.out.println("setting id: " + myid);

        this.myid = myid;
    }

    /**
     * Gets md5hash.
     *
     * @return Value for md5hash.
     */
    public String getMd5hash() {


        return md5hash;
    }

    /**
     * Sets md5hash.
     *
     * @param md5hash New value for md5hash.
     */
    public void setMd5hash(String md5hash) {
        System.out.println("setting md5: " + md5hash);
        this.md5hash = md5hash;
    }

    /** {@inheritDoc} */
    @Override public boolean equals(Object o) {
        if (this == o)
            return true;

        if (!(o instanceof UuidTest))
            return false;

        UuidTest that = (UuidTest)o;

        if (myid != null ? !myid.equals(that.myid) : that.myid != null)
            return false;

        if (md5hash != null ? !md5hash.equals(that.md5hash) : that.md5hash != 
null)
            return false;

        return true;
    }

    /** {@inheritDoc} */
    @Override public int hashCode() {
        int res = myid != null ? myid.hashCode() : 0;

        res = 31 * res + (md5hash != null ? md5hash.hashCode() : 0);

        return res;
    }

    /** {@inheritDoc} */
    @Override public String toString() {
        return "UuidTest [myid=" + myid +
            ", md5hash=" + md5hash +
            "]";
    }
}

###key class

/**
 * UuidTestKey definition.
 *
 * Code generated by Apache Ignite Schema Import utility: 06/26/2015.
 */
public class UuidTestKey implements Serializable {
    /** */
    private static final long serialVersionUID = 0L;

    /** Value for myid. */
    private Object myid;

    /**
     * Empty constructor.
     */
    public UuidTestKey() {
        // No-op.
    }

    /**
     * Full constructor.
     */
    public UuidTestKey(
        Object myid
    ) {
        this.myid = myid;
    }

    /**
     * Gets myid.
     *
     * @return Value for myid.
     */
    public Object getMyid() {
        return myid;
    }

    /**
     * Sets myid.
     *
     * @param myid New value for myid.
     */
    public void setMyid(Object myid) {
        this.myid = myid;
    }

    /** {@inheritDoc} */
    @Override public boolean equals(Object o) {
        if (this == o)
            return true;

        if (!(o instanceof UuidTestKey))
            return false;

        UuidTestKey that = (UuidTestKey)o;

        if (myid != null ? !myid.equals(that.myid) : that.myid != null)
            return false;

        return true;
    }

    /** {@inheritDoc} */
    @Override public int hashCode() {
        int res = myid != null ? myid.hashCode() : 0;

        return res;
    }

    /** {@inheritDoc} */
    @Override public String toString() {
        return "UuidTestKey [myid=" + myid +
            "]";
    }
}

##cache config


/**
 * CacheConfig definition.
 *
 * Code generated by Apache Ignite Schema Import utility: 06/26/2015.
 */
public class CacheConfig {
    /**
    * Configure cache.
    *
    * @param name Cache name.
    * @param storeFactory Cache store factory.
    */
    public static <K, V> CacheConfiguration<K, V> cache(String name, 
Factory<CacheStore<K, V>> storeFactory) {
        if (storeFactory == null)
             throw new IllegalArgumentException("Cache store factory cannot be 
null.");

        CacheConfiguration<K, V> ccfg = new CacheConfiguration<>(name);

        ccfg.setCacheStoreFactory(storeFactory);
        ccfg.setReadThrough(true);
        ccfg.setWriteThrough(true);
        ccfg.setBackups(0);

        // Configure cache types.
        Collection<CacheTypeMetadata> meta = new ArrayList<>();

        // uuid_test.
        CacheTypeMetadata type = new CacheTypeMetadata();

        meta.add(type);

        type.setDatabaseSchema("TEST");
        type.setDatabaseTable("uuid_test");
        type.setKeyType(UuidTestKey.class.getName());
        type.setValueType(UuidTest.class.getName());

        // Key fields for uuid_test.
        Collection<CacheTypeFieldMetadata> keys = new ArrayList<>();
        keys.add(new CacheTypeFieldMetadata("myid", Types.BINARY, "myid", 
Object.class));
        type.setKeyFields(keys);

        // Value fields for uuid_test.
        Collection<CacheTypeFieldMetadata> vals = new ArrayList<>();
        vals.add(new CacheTypeFieldMetadata("myid", Types.BINARY, "myid", 
Object.class));
        vals.add(new CacheTypeFieldMetadata("md5hash", Types.VARCHAR, 
"md5hash", String.class));
        type.setValueFields(vals);

        // Query fields for uuid_test.
        Map<String, Class<?>> qryFlds = new LinkedHashMap<>();

        qryFlds.put("myid", Object.class);
        qryFlds.put("md5hash", String.class);

        type.setQueryFields(qryFlds);

        // Ascending fields for uuid_test.
        Map<String, Class<?>> ascFlds = new LinkedHashMap<>();

        ascFlds.put("myid", Object.class);

        type.setAscendingFields(ascFlds);

        ccfg.setTypeMetadata(meta);

        return ccfg;
    }
}


##actual application


public static void main(String args[]){

    CacheConfiguration ccfg = CacheConfig.cache(CACHE_NAME, new 
Factory<CacheStore<UuidTestKey, UuidTest>>() {
        @Override
        public CacheStore<UuidTestKey, UuidTest> create() {
            CacheJdbcPojoStore<UuidTestKey, UuidTest> store = new 
CacheJdbcPojoStore<>();

            MysqlDataSource dataSource = new MysqlDataSource();

            dataSource.setUrl("jdbc:mysql://localhost:3306");
            dataSource.setUser("blag");
            dataSource.setPassword("blah");

            store.setDataSource(dataSource);

            return store;
        }
    });

    ccfg.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL);


    IgniteConfiguration cfg = new IgniteConfiguration();

    cfg.setPeerClassLoadingEnabled(false); //from config

    OptimizedMarshaller opm = new OptimizedMarshaller();
    opm.setRequireSerializable(true);
    cfg.setMarshaller(opm);


    System.out.println("start ignite");
    Ignite ignite = Ignition.start(cfg);
    System.out.println("started ignite");

    IgniteCache<UuidTestKey, UuidTest> bob = ignite.getOrCreateCache(ccfg);

    System.out.println("loading cache");
    bob.loadCache(null);
    System.out.println("loaded cache");

    for(Cache.Entry<UuidTestKey, UuidTest> entry : bob ){
        System.out.println("############################");
        System.out.println("KEY: " + entry.getKey().toString());

        if( entry.getValue() != null ){
            System.out.println("not null");
        } else {
            System.out.println("null value");
        }

        System.out.println("############################");
    }

}





So as I stated above, when im loading the cache I can see it actually create 
the objects, however if I try and loop over those entries the value is always 
null..

##example output

started ignite
loading cache
setting id: [B@31dbcc67
setting md5: 1ce4ccbc5d0d0856c20320af47082f90
setting id: [B@1e82e976
setting md5: 8938399f02eba8d8c686d138f8a22948
setting id: [B@6d387443
setting md5: ae0548a8ea6595b54c7a78dc90b73226
setting id: [B@392d642a
setting md5: 213d360701055e707442348f5fae4900
setting id: [B@4ac3bf8e
setting md5: 673bdd0dcd9f4079c615e855b9eb36da
setting id: [B@5dfec287
setting md5: af4c86aaabcfa8c908af5ed57643f329
setting id: [B@409ae7a8
setting md5: 74fcc8fb1aa4c0c7b73b259e6ecbbdd8
setting id: [B@6857421c
setting md5: 534dd648af15d8d2c148ab1b36699393
setting id: [B@7b6b9fa7
setting md5: 1d7c2da5ddeb618cdab01be628a83914
setting id: [B@5ee53ff4
setting md5: 1302e7bf2de21047fdaa885e7c1aabc5
setting id: [B@7f3a3b4e
setting md5: 38f4887816ef90ece12ad73a24818d48
setting id: [B@3a5250cf
setting md5: c912dec6d3ed3a7407ac1251f8ad13aa
setting id: [B@70dde5ec
setting md5: 5958b700438901fb4db7f10eef6f675e
loaded cache
############################
KEY: UuidTestKey [myid=[B@16e248af]
null value
############################
############################
KEY: UuidTestKey [myid=[B@378a230]
null value
############################
############################
KEY: UuidTestKey [myid=[B@761c3f71]
null value
############################
############################
KEY: UuidTestKey [myid=[B@20078e95]
null value
############################
############################
KEY: UuidTestKey [myid=[B@aaae957]
null value



I am positive I am doing something slightly wrong but I can't for the life of 
me work out what!

Thanks,


--

Dave












Reply via email to