I created table with DDL, and tried to put some data using cache.put. But when the affinity key is set at the table, an error occurs that the affinity key does not fit when put data using cache.
Please help me to solve this problem.
CREATE TABLE IF NOT EXISTS Person (
CITY_ID int,
ID int,
NAME varchar,
AGE int,
COMPANY varchar,
PRIMARY KEY (CITY_ID, ID)
) WITH "template=partitioned,backups=1,affinity_key=ID,CACHE_NAME=Person,KEY_TYPE=test.PersonKey,VALUE_TYPE=test.PersonValue";
My .NET code is below.
namespace test
{
class PersonKey
{
[QuerySqlField]
public int CITY_ID;
[AffinityKeyMapped]
public int ID;
}
class PersonValue : PersonKey
{
[QuerySqlField]
public string NAME, COMPANY;
[QuerySqlField]
public int AGE;
}
class IgniteTest
{
public static void Main()
{
try
{
IgniteClientConfiguration cfg = new IgniteClientConfiguration
{
Endpoints = new[] { "127.0.0.1:10800" }
};
using (var client = Ignition.StartClient(cfg))
{
var cache = client.GetOrCreateCache<PersonKey, PersonValue>("Person");
PersonKey tableKey = new PersonKey();
PersonValue tableValue = new PersonValue();
tableKey.ID = 2;
tableKey.CITY_ID = 2;
tableValue.ID = 2;
tableValue.CITY_ID = 2;
tableValue.NAME = "2";
tableValue.AGE = 2;
tableValue.COMPANY = "2";
cache.Put(tableKey, tableValue);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
}
}
client side error message is below
Apache.Ignite.Core.Client.IgniteClientException: Binary type has different affinity key fields [typeName=test.PersonValue, affKeyFieldName1=null, affKeyFieldName2=ID]
at Apache.Ignite.Core.Impl.Client.ClientSocket.DecodeResponse[T](BinaryHeapStream stream, Func`2 readFunc, Func`3 errorFunc)
at Apache.Ignite.Core.Impl.Client.ClientSocket.DoOutInOp[T](ClientOp opId, Action`1 writeAction, Func`2 readFunc, Func`3 errorFunc)
at Apache.Ignite.Core.Impl.Client.ClientFailoverSocket.DoOutInOp[T](ClientOp opId, Action`1 writeAction, Func`2 readFunc, Func`3 errorFunc)
at Apache.Ignite.Core.Impl.Binary.BinaryProcessorClient.PutBinaryTypes(ICollection`1 types)
at Apache.Ignite.Core.Impl.Binary.Marshaller.FinishMarshal(BinaryWriter writer)
at Apache.Ignite.Core.Impl.Client.ClientRequestContext.FinishMarshal()
at Apache.Ignite.Core.Impl.Client.ClientSocket.WriteMessage(Action`1 writeAction, ClientOp opId)
at Apache.Ignite.Core.Impl.Client.ClientSocket.DoOutInOp[T](ClientOp opId, Action`1 writeAction, Func`2 readFunc, Func`3 errorFunc)
at Apache.Ignite.Core.Impl.Client.ClientFailoverSocket.DoOutInOpAffinity[T,TKey](ClientOp opId, Action`1 writeAction, Func`2 readFunc, Int32 cacheId, TKey key, Func`3 errorFunc)
at Apache.Ignite.Core.Impl.Client.Cache.CacheClient`2.DoOutInOpAffinity[T](ClientOp opId, TK key, TV val, Func`2 readFunc)
at Apache.Ignite.Core.Impl.Client.Cache.CacheClient`2.Put(TK key, TV val)
at test.IgniteTest.Main() in E:\GHLee\dev\cs\GridgainTest\Program.cs:line 53 [StatusCode=Fail]
And server side error message is here
class org.apache.ignite.binary.BinaryObjectException: Binary type has different affinity key fields [typeName=test.PersonValue, affKeyFieldName1=null, affKeyFieldName2=ID]
at org.apache.ignite.internal.binary.BinaryUtils.mergeMetadata(BinaryUtils.java:998)
at org.apache.ignite.internal.processors.cache.binary.BinaryMetadataTransport.requestMetadataUpdate(BinaryMetadataTransport.java:210)
at org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl.addMeta(CacheObjectBinaryProcessorImpl.java:549)
at org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl$1.addMeta(CacheObjectBinaryProcessorImpl.java:239)
at org.apache.ignite.internal.binary.BinaryContext.updateMetadata(BinaryContext.java:1315)
at org.apache.ignite.internal.processors.platform.client.binary.ClientBinaryTypePutRequest.process(ClientBinaryTypePutRequest.java:50)
at org.apache.ignite.internal.processors.platform.client.ClientRequestHandler.handle(ClientRequestHandler.java:100)
at org.apache.ignite.internal.processors.odbc.ClientListenerNioListener.onMessage(ClientListenerNioListener.java:256)
at org.apache.ignite.internal.processors.odbc.ClientListenerNioListener.onMessage(ClientListenerNioListener.java:61)
at org.apache.ignite.internal.util.nio.GridNioFilterChain$TailFilter.onMessageReceived(GridNioFilterChain.java:278)
at org.apache.ignite.internal.util.nio.GridNioFilterAdapter.proceedMessageReceived(GridNioFilterAdapter.java:108)
at org.apache.ignite.internal.util.nio.GridNioAsyncNotifyFilter$3.body(GridNioAsyncNotifyFilter.java:135)
at org.apache.ignite.internal.util.worker.GridWorker.run(GridWorker.java:119)
at org.apache.ignite.internal.util.worker.GridWorkerPool$1.run(GridWorkerPool.java:69)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:829)