Apache Ignite Linq over Sql 无法解析 java 类 [英] Apache Ignite Linq over Sql Failed to resolve java class

查看:18
本文介绍了Apache Ignite Linq over Sql 无法解析 java 类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在对使用 sql api 创建的表执行 linq.

I am doing linq over tables I created using sql api.

我创建了表:

var cfg = new CacheClientConfiguration(
    "PUBLIC",
    new QueryEntity(typeof(object), typeof(object)))
    {
        SqlSchema = "PUBLIC",
        CacheMode = CacheMode.Partitioned
    };

var cache = cli.GetOrCreateCache<object, object>(cfg);
cache.Query(new SqlFieldsQuery(@"
    CREATE TABLE IF NOT EXISTS Things 
    (
        Id UUID,
        Name VARCHAR,
        EffectiveDate TIMESTAMP,

        PRIMARY KEY(Id)
    )
    WITH ""TEMPLATE = PARTITIONED,
           CACHE_NAME = consoleappserver.Thing,
           VALUE_TYPE = consoleappserver.Thing""
")).GetAll();

我放了一些种子数据:

cache.Query(new SqlFieldsQuery(@"
    INSERT INTO Things (Id, Name, EffectiveDate) VALUES (?,?,?)",
    Guid.NewGuid(), "Test Name 1", DateTime.SpecifyKind(DateTime.Today, DateTimeKind.Utc))).GetAll();

cache.Query(new SqlFieldsQuery(@"
    INSERT INTO Things (Id, Name, EffectiveDate) VALUES (?,?,?)",
    Guid.NewGuid(), "Test Name 2", DateTime.SpecifyKind(DateTime.Today.AddDays(1), DateTimeKind.Utc))).GetAll();

cache.Query(new SqlFieldsQuery(@"
    INSERT INTO Things (Id, Name, EffectiveDate) VALUES (?,?,?)",
    Guid.NewGuid(), "Test Name 3", DateTime.SpecifyKind(DateTime.Today.AddDays(2), DateTimeKind.Utc))).GetAll();

这是我的 linq 查询:

Here is my linq query:

var cache = cli.GetCache<Guid, Thing>("consoleappserver.Thing");
var things = cache.AsCacheQueryable();
var effectiveDate = DateTime.SpecifyKind(DateTime.Today, DateTimeKind.Utc);
things = things.Where(t => t.Value.EffectiveDate <= effectiveDate);

foreach (var kv in things)
{
    Console.WriteLine("Things #{0} '{1}'", kv.Value.Id, kv.Value.Name);
}

这是我用于映射的 C# 类:

Here is the C# class I use for mapping:

public class Thing
{
    [QuerySqlField(Name = "ID")]
    public Guid Id { get; set; }

    [QuerySqlField(Name = "NAME")]
    public string Name { get; set; }

    [QuerySqlField(Name = "EFFECTIVEDATE")]
    public DateTime EffectiveDate { get; set; }
}

这是我尝试迭代事物时遇到的错误:

And here is the error I get when I try to iterate over things:

Apache.Ignite.Core.Client.IgniteClientException:
'无法解析 .NET 中的 Java 类'consoleappserver.Thing' [platformId=1, typeId=298456301].'

Apache.Ignite.Core.Client.IgniteClientException:
'Failed to resolve Java class 'consoleappserver.Thing' in .NET [platformId=1, typeId=298456301].'

这是记录的完整错误:

[11:00:18,731][SEVERE][client-connector-#110][ClientListenerNioListener] 无法处理客户端请求 [req=o.a.i.i.processors.platform.client.binary.ClientBinaryTypeNameGetRequest@250d2f65]class org.apache.ignite.IgniteException:无法解析 .NET [platformId=1, typeId=298456301] 中的 Java 类consoleappserver.Thing".在 org.apache.ignite.internal.processors.platform.client.binary.ClientBinaryTypeNameGetRequest.process(ClientBinaryTypeNameGetRequest.java:57)在 org.apache.ignite.internal.processors.platform.client.ClientRequestHandler.handle(ClientRequestHandler.java:93)在 org.apache.ignite.internal.processors.odbc.ClientListenerNioListener.onMessage(ClientListenerNioListener.java:202)在 org.apache.ignite.internal.processors.odbc.ClientListenerNioListener.onMessage(ClientListenerNioListener.java:58)在 org.apache.ignite.internal.util.nio.GridNioFilterChain$TailFilter.onMessageReceived(GridNioFilterChain.java:278)在 org.apache.ignite.internal.util.nio.GridNioFilterAdapter.proceedMessageReceived(GridNioFilterAdapter.java:108)在 org.apache.ignite.internal.util.nio.GridNioAsyncNotifyFilter$3.body(GridNioAsyncNotifyFilter.java:135)在 org.apache.ignite.internal.util.worker.GridWorker.run(GridWorker.java:119)在 org.apache.ignite.internal.util.worker.GridWorkerPool$1.run(GridWorkerPool.java:69)在 java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)在 java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)在 java.base/java.lang.Thread.run(Thread.java:834)引起:java.lang.ClassNotFoundException:无法解析 .NET [platformId=1, typeId=298456301] 中的 Java 类consoleappserver.Thing".在 org.apache.ignite.internal.MarshallerContextImpl.getClassName(MarshallerContextImpl.java:400)在 org.apache.ignite.internal.MarshallerContextImpl.getClassName(MarshallerContextImpl.java:333)在 org.apache.ignite.internal.processors.platform.client.binary.ClientBinaryTypeNameGetRequest.process(ClientBinaryTypeNameGetRequest.java:52)……还有 11 个

[11:00:18,731][SEVERE][client-connector-#110][ClientListenerNioListener] Failed to process client request [req=o.a.i.i.processors.platform.client.binary.ClientBinaryTypeNameGetRequest@250d2f65] class org.apache.ignite.IgniteException: Failed to resolve Java class 'consoleappserver.Thing' in .NET [platformId=1, typeId=298456301]. at org.apache.ignite.internal.processors.platform.client.binary.ClientBinaryTypeNameGetRequest.process(ClientBinaryTypeNameGetRequest.java:57) at org.apache.ignite.internal.processors.platform.client.ClientRequestHandler.handle(ClientRequestHandler.java:93) at org.apache.ignite.internal.processors.odbc.ClientListenerNioListener.onMessage(ClientListenerNioListener.java:202) at org.apache.ignite.internal.processors.odbc.ClientListenerNioListener.onMessage(ClientListenerNioListener.java:58) 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:834) Caused by: java.lang.ClassNotFoundException: Failed to resolve Java class 'consoleappserver.Thing' in .NET [platformId=1, typeId=298456301]. at org.apache.ignite.internal.MarshallerContextImpl.getClassName(MarshallerContextImpl.java:400) at org.apache.ignite.internal.MarshallerContextImpl.getClassName(MarshallerContextImpl.java:333) at org.apache.ignite.internal.processors.platform.client.binary.ClientBinaryTypeNameGetRequest.process(ClientBinaryTypeNameGetRequest.java:52) ... 11 more

推荐答案

由于表是用 SQL 定义的,因此 Ignite 不知道 Thing 类型.在查询前使用以下调用强制二进制类型注册:

Since the table is defined with SQL, Thing type is not known to Ignite. Use the following call before the query to force binary type registration:

cli.GetBinary().GetBinaryType(typeof(Thing));

这个调用可以在 Ignition.StartClient 之后每个客户端实例执行一次.

This call can be done once per client instance after Ignition.StartClient.

这篇关于Apache Ignite Linq over Sql 无法解析 java 类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆