I ran below SQL from Ignite Sqlline which creates a table and inserts one
entry. I am trying to query that entry using cache api. However, the value
always returns null.
############## SQL ################
CREATE TABLE SIMPLE_TABLE (
ACCOUNT_ID INT,
SECURITY_ALIAS INT,
POSITION_TYPE VARCHAR(50),
EFFECTIVE_DATE TIMESTAMP,
GROSS_RETURN DOUBLE,
PRIMARY KEY (ACCOUNT_ID, SECURITY_ALIAS, POSITION_TYPE, EFFECTIVE_DATE)
)
WITH "template=partitioned, backups=1, affinityKey=ACCOUNT_ID,
KEY_TYPE=com.xyz.ie.SimpleKey, VALUE_TYPE=com.xyz.ie.SimpleVal";
INSERT INTO SIMPLE_TABLE VALUES (100, 200, 'PT0', '2018-11-01', 1000.0);
##################################
< SimpleKey.java >
package com.xyz.ie;
import org.apache.ignite.cache.affinity.AffinityKeyMapped;
import java.sql.Timestamp;
public class SimpleKey {
@AffinityKeyMapped
private int ACCOUNT_ID;
private int SECURITY_ALIAS;
private String POSITION_TYPE;
private Timestamp EFFECTIVE_DATE;
public SimpleKey(int accountId, int securityAlias, String positionType,
Timestamp effectiveDate) {
this.ACCOUNT_ID = accountId;
this.SECURITY_ALIAS = securityAlias;
this.POSITION_TYPE = positionType;
this.EFFECTIVE_DATE = effectiveDate;
}
}
<SimpleVal.java>
package com.xyz.ie;
public class SimpleVal {
private double GROSS_RETURN;
public SimpleVal(double grossReturn) {
this.GROSS_RETURN = grossReturn;
}
public double getGrossReturn() {
return GROSS_RETURN;
}
public void setGrossReturn(double grossReturn) {
this.GROSS_RETURN = grossReturn;
}
}
Here is my code that tries to read the entry.
IgniteCache<SimpleKey, SimpleVal> simpleTableCache =
ignite.cache("SQL_PUBLIC_SIMPLE_TABLE");
// cacheSize evaluates to 1 as expected.
int cacheSize = simpleTableCache.size(CachePeekMode.PRIMARY);
SimpleKey key = new SimpleKey(100, 200, "PT0", Timestamp.valueOf("2018-11-01
00:00:00"));
*// I expect val below to contain the one entry in the cache. However, it is
null.*
SimpleVal val = simpleTableCache.get(key);
if (val == null) {
System.out.println("Can't find the key.");
}
Could someone point out what I am doing wrong here and why it is not finding
the key in the cache?
--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/