I was running as a thick client.
This also works:
// Create cache
Ignition.setClientMode(true);
try (Ignite ignite = Ignition.start(AppConfiguration.getConfiguration())) {
LinkedHashMap<String,String> fields = new LinkedHashMap<>();
fields.put("uid", Integer.class.getName());
fields.put("attr1", String.class.getName());
fields.put("attr2", String.class.getName());
CacheConfiguration<Integer,SampleBean> cacheConfiguration = new
CacheConfiguration<>();
cacheConfiguration.setName("FUTURE_TEST_CACHE")
.setQueryEntities(Arrays.asList(
new QueryEntity()
.setKeyType(Integer.class.getName())
.setKeyFieldName("uid")
.setValueType("stackoverflow.SampleBean")
.setFields(fields)
.setIndexes(Arrays.asList(new QueryIndex("attr1")))
));
IgniteCache<Integer,SampleBean> cc =
ignite.getOrCreateCache(cacheConfiguration);
}
// Access cache
ClientConfiguration clientConfiguration = new ClientConfiguration();
clientConfiguration.setAddresses("127.0.0.1:10800");
try (IgniteClient igniteClient = Ignition.startClient(clientConfiguration))
{
ClientCache<Integer,SampleBean> cc =
igniteClient.cache("FUTURE_TEST_CACHE");
for (int i = 1; i < 10; i++) {
SampleBean bean = new SampleBean();
bean.setUid(100 + i);
bean.setAttr1("attribute1 10" + i);
bean.setAttr2("attribute2 10" + i);
cc.put(bean.getUid(), bean);
}// 1. initialized cache data by KV-mode
System.out.println("ignite cache putting 10 element over.");
SampleBean bean = cc.get(105);// 1.a load by KV mode
System.out.format("Load from cache: '%s'.\n", bean);
cc.query(new SqlFieldsQuery("insert into SampleBean(uid, attr1, attr2)
values(?, ?, ?) ").setArgs(206, "attribute1 106", "attribute2 106"))
.getAll();// 2.a. Insert first
List list = cc.query(new SqlFieldsQuery("select * from SampleBean where
attr1 like 'attribute1%'"))
.getAll();// 3. Here, if using "2.a"can get result; otherwise
only with "1" to initialize, will be empty list ever.
System.out.printf("query from cache is: %s.\n", list);
}
}
> On 28 May 2021, at 10:43, tankmarshal <[email protected]> wrote:
>
> Yes, I know, but you may have a mistake: with your code, your application run
> as a ignite server, too.
>
> I was trying the scene that Ignite running as a server, and application just
> running in client-mode. So, client have no need to set queryEntity
> attributes, cause it's already configured in the server config file.
>
> you may try the scene, do a test.
>
>
>
> --
> Sent from: http://apache-ignite-users.70518.x6.nabble.com/