Apache Cayenne“类未与Cayenne映射”

时间:2019-02-22 21:29:21

标签: java apache-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();

1 个答案:

答案 0 :(得分:0)

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

if /?

IIRC tag <domains> is unexpected at [36,2]. The following tags are allowed here: [domain] 是3.1之前的版本,而运行时看起来是3.1或4.0。所以我建议如下:

  • 找出运行时使用的Cayenne版本。
  • 下载此版本的Cayenne发行版。
  • 使用发行版中的CayenneModeler应用程序打开“ cayenne.xml”文件。它应该询问您是否要升级。
  • 继续升级。
  • 很有可能该项目将从“ cayenne.xml”重命名为“ cayenne-project.xml”,因此请确认新名称是什么,并在创建<domains>时使用它