我正在使用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();
答案 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。所以我建议如下:
<domains>
时使用它