【问题标题】:Apache Cayenne "Class is not mapped with Cayenne"Apache Cayenne“类未与 Cayenne 映射”
【发布时间】:2019-02-22 21:29:20
【问题描述】:

我正在使用 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();

【问题讨论】:

    标签: java apache-cayenne


    【解决方案1】:

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

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

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

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

    【讨论】:

    • 添加了我的日志输出和我的ServerRuntime初始化
    • 刚刚更改了我上面的回复以说明新信息。
    • 我意识到我的建模器正在运行不同的版本,已修复!谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多