Apache Cayenne“类未与 Cayenne 映射”
Posted
技术标签:
【中文标题】Apache Cayenne“类未与 Cayenne 映射”【英文标题】:Apache Cayenne "Class is not mapped with 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();
【问题讨论】:
【参考方案1】:从启动日志中可以看出,您有一个旧的“cayenne.xml”文件正在运行一个较新的运行时:
tag <domains> is unexpected at [36,2]. The following tags are allowed here: [domain]
IIRC <domains>
是 3.1 之前的版本,而运行时看起来像 3.1 或 4.0。所以我建议如下:
ServerRuntime
时使用它
【讨论】:
添加了我的日志输出和我的ServerRuntime
初始化
刚刚更改了我上面的回复以说明新信息。
我意识到我的建模器正在运行不同的版本,已修复!谢谢!以上是关于Apache Cayenne“类未与 Cayenne 映射”的主要内容,如果未能解决你的问题,请参考以下文章
Apache Cayenne:java.io.StreamCorruptedException