阿帕奇卡宴 "Class is not mapped with Cayenne"

Apache Cayenne "Class is not mapped with Cayenne"

我正在使用 Apache Cayenne 存储数据并根据文件检查数据以查看文件是否已更改。我目前有一种方法可以将数据插入我的数据库,但我收到:

Exception in thread "main" java.lang.IllegalArgumentException: Class is not mapped with Cayenne: edu.ndsu.eci.duo_demo.persist.Integrations
    at org.apache.cayenne.access.DataContext.newObject(DataContext.java:471)
    at edu.ndsu.eci.duo_demo.util.IntegrationService.insertData(IntegrationService.java:31)
    at edu.ndsu.eci.duo_demo.main.ServiceMain.main(ServiceMain.java:55)

我的方法:

public static void insertData(Integration i, ObjectContext context) {
    Integrations integ = context.newObject(Integrations.class);
    integ.setName(i.getName());
    integ.setEnrollPolicy(i.getEnrollPolicy());

    List<String> ipWhitelist = i.getIpWhitelist();
    String ip = "[";
    if(ipWhitelist.size() > 0)
      ip += "\"";
    for(int j = 0; j < ipWhitelist.size(); j++) {
      ip += ipWhitelist.get(j) + "\"";
      if(j < ipWhitelist.size()-1)
        ip += ",\"";
    }
    ip += "]";

    integ.setIpWhitelist(ip);
    context.commitChanges();
  }

编辑

我的日志输出:

[main] DEBUG org.apache.cayenne.configuration.server.DataDomainProvider  - starting configuration loading: [cayenne.xml]
[main] DEBUG org.apache.cayenne.configuration.server.DataDomainProvider  - starting configuration loading: [cayenne.xml]
[main] INFO  org.apache.cayenne.configuration.XMLDataChannelDescriptorLoader  - Loading XML configuration resource from file:/home/stkarsch/git/duo-integration-verification/target/classes/cayenne.xml
[main] INFO org.apache.cayenne.configuration.XMLDataChannelDescriptorLoader  - Loading XML configuration resource from file:/home/stkarsch/git/duo-integration-verification/target/classes/cayenne.xml
[main] INFO  org.apache.cayenne.configuration.XMLDataChannelDescriptorLoader  - tag <domains> is unexpected at [36,2]. The following tags are allowed here: [domain]
[main] INFO org.apache.cayenne.configuration.XMLDataChannelDescriptorLoader  - tag <domains> is unexpected at [36,2]. The following tags are allowed here: [domain]
[main] DEBUG org.apache.cayenne.configuration.server.DataDomainProvider  - finished configuration loading in 22 ms.
[main] DEBUG org.apache.cayenne.configuration.server.DataDomainProvider  - finished configuration loading in 22 ms.
[main] DEBUG org.apache.cayenne.access.DataRowStore  - DataRowStore property cayenne.DataRowStore.snapshot.size = 10000
[main] DEBUG org.apache.cayenne.access.DataRowStore  - DataRowStore property cayenne.DataRowStore.snapshot.size = 10000

初始化我的ServerRuntime

ServerRuntime run = ServerRuntime.builder().addConfig("cayenne.xml").build();
ObjectContext context = run.getContext();

从启动日志看来,您有一个旧的 "cayenne.xml" 文件 运行 一个较新的运行时:

 tag <domains> is unexpected at [36,2]. The following tags are allowed here: [domain] 

IIRC <domains> 是 3.1 之前的版本,而运行时看起来像 3.1 或 4.0。所以我建议如下:

  • 找出运行时使用的 Cayenne 版本。
  • 下载此版本的 Cayenne 发行版。
  • 使用发行版中的 CayenneModeler 应用程序打开 "cayenne.xml" 文件。它应该询问你是否要升级。
  • 继续升级。
  • 项目很可能会从"cayenne.xml"重命名为"cayenne-project.xml"所以确认新名字是什么,在创建的时候使用ServerRuntime