OrientDB 3.0.4 Java OValidationException:该字段已声明为EMBEDDEDLIST,但使用了不兼容的类型

OrientDB 3.0.4 Java OValidationException:该字段已声明为EMBEDDEDLIST,但使用了不兼容的类型,java,orientdb,embeddedlist,Java,Orientdb,Embeddedlist,我正在使用OrientDB 3.0.4版 使用Java和orientdb client.3.0.4 Java驱动程序/库 我尝试使用EMBEDDEDLIST类型,如下所示: public void insertProfileTest() throws JsonProcessingException { LOGGER.info(dbSession.getMetadata().getSchema().getClass(Profile.class).getProperty("name"

我正在使用OrientDB 3.0.4版 使用Java和orientdb client.3.0.4 Java驱动程序/库

我尝试使用EMBEDDEDLIST类型,如下所示:

public void insertProfileTest() throws JsonProcessingException { LOGGER.info(dbSession.getMetadata().getSchema().getClass(Profile.class).getProperty("name").toString()); LOGGER.info(dbSession.getMetadata().getSchema().getClass(Profile.class).getProperty("phone").toString()); LOGGER.info(dbSession.getMetadata().getSchema().getClass(Phone.class).getProperty("number").toString()); // Init Profile userProfile = new Profile("Jane Doe"); Phone homePhone = new Phone("212"); Phone cellPhone = new Phone("718"); userProfile.addPhone(homePhone); userProfile.addPhone(cellPhone); final String json = MAPPER.writeValueAsString(userProfile); LOGGER.info("Profile JSON:" + json); LOGGER.info("Phone Class :" + userProfile.getPhone().getClass().getName()); // DB List phoneVertexList = new ArrayList(); for (Phone phone: userProfile.getPhone()) { final OVertex phoneVertex = dbSession.newVertex("Phone"); phoneVertex.setProperty("number", phone.getNumber()); phoneVertexList.add(phoneVertex); } final OVertex profileVertex = dbSession.newVertex("Profile"); profileVertex.setProperty("name", userProfile.getName()); profileVertex.setProperty("phone", phoneVertexList, OType.EMBEDDEDLIST); profileVertex.save(); } select * from Profile +----+-----+-------+--------+-------------------------------------+ |# |@RID |@CLASS |name |phone | +----+-----+-------+--------+-------------------------------------+ |0 |#41:0|Profile|Jane Doe|[Phone{number:212},Phone{number:718}]| +----+-----+-------+--------+-------------------------------------+ select * from Phone +----+-----+------+------+ |# |@RID |@CLASS|number| +----+-----+------+------+ |0 |#33:0|Phone |212 | |1 |#34:0|Phone |718 | +----+-----+------+------+ 数据库模式:
使用OrientDB控制台,可以完成以下工作: 使用Java失败: 尝试创建具有两个存储为列表(ArrayList)的Phone对象的配置文件顶点时,代码失败,出现以下异常:

com.orientechnologies.orient.core.exception.OValidationException: The field 'Profile.phone' has been declared as EMBEDDEDLIST but an incompatible type is used. Value: Phone{number:212} DB name="test" Error Code="4" at com.orientechnologies.orient.core.record.impl.ODocument.validateEmbedded(ODocument.java:814) com.orientechnologies.orient.core.exception.OValidationException:字段“Profile.phone”已声明为EMBEDDEDLIST,但使用了不兼容的类型。值:电话{号码:212} DB name=“测试” 错误代码=“4” 在com.orientechnologies.orient.core.record.impl.ODocument.validateEmbedded(ODocument.java:814) 代码如下: public void insertProfileTest()引发JsonProcessingException{ LOGGER.info(dbSession.getMetadata().getSchema().getClass(Profile.class).getProperty(“name”).toString()); LOGGER.info(dbSession.getMetadata().getSchema().getClass(Profile.class).getProperty(“电话”).toString()); LOGGER.info(dbSession.getMetadata().getSchema().getClass(Phone.class).getProperty(“number”).toString()); //初始化 Profile userProfile=新配置文件(“Jane Doe”); 电话homePhone=新电话(“212”); 手机=新手机(“718”); userProfile.addPhone(家庭电话); userProfile.addPhone(手机); 最终字符串json=MAPPER.writeValueAsString(userProfile); info(“Profile JSON:+JSON”); LOGGER.info(“电话类:”+userProfile.getPhone().getClass().getName()); //分贝 最终OVertex profileVertex=dbSession.newVertex(“轮廓”); profileVertex.setProperty(“name”,userProfile.getName()); profileVertex.setProperty(“phone”,userProfile.getPhone(),OType.EMBEDDEDLIST); //无法保存- //字段“Profile.phone”已声明为EMBEDDEDLIST,但使用了不兼容的类型。值:com.sample.Profile。Phone@32f232a5 profileVertex.save(); } 以下是输出: 14:11:00.124[主]INFO com.sample.profile.ProfileTest-初始化开始 14:11:01.187[主]INFO com.sample.profile.ProfileTest-OrientDB[远程:本地主机/测试]状态:[打开] 14:11:01.191[主]信息com.sample.profile.ProfileTest-名称(类型=字符串) 14:11:01.192[主]INFO com.sample.profile.ProfileTest-电话(类型=嵌入列表) 14:11:01.192[main]INFO com.sample.profile.ProfileTest-编号(类型=字符串) 14:11:01.233[main]INFO com.sample.profile.ProfileTest-profile JSON:{“name”:“Jane Doe1”,“phone”:[{“number”:“212”},{“number”:“718”} 14:11:01.234[main]INFO com.sample.profile.ProfileTest-电话类:java.util.ArrayList 2018年7月12日下午2:11:01 com.orientechnologies.common.log.OLogManager日志 信息:定向引擎正在关闭。。。 com.orientechnologies.orient.core.exception.OValidationException:字段“Profile.phone”已声明为EMBEDDEDLIST,但使用了不兼容的类型。值:电话{号码:212} DB name=“测试” 错误代码=“4” 在com.orientechnologies.orient.core.record.impl.ODocument.validateEmbedded(ODocument.java:814) 在com.orientechnologies.orient.core.record.impl.ODocument.validateField(ODocument.java:601)上 位于com.orientechnologies.orient.core.record.impl.ODocument.validate(ODocument.java:2365) 位于com.orientechnologies.orient.core.db.document.ODatabaseDocumentAbstract.saveInternal(ODatabaseDocumentAbstract.java:2057) 位于com.orientechnologies.orient.core.db.document.ODatabaseDocumentAbstract.save(ODatabaseDocumentAbstract.java:2042) 在com.orientechnologies.orient.core.db.document.ODatabaseDocumentAbstract.save上(ODatabaseDocumentAbstract.java:84) 位于com.orientechnologies.orient.core.record.impl.ODocument.save(ODocument.java:2109) 在com.orientechnologies.orient.core.record.impl.ODocument.save上(ODocument.java:2100) 位于com.orientechnologies.orient.core.record.impl.ODocument.save(ODocument.java:63) 在com.sample.profile.ProfileTest.insertProfileTest(ProfileTest.java:98)上 在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)处 位于sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 在sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)中 位于java.lang.reflect.Method.invoke(Method.java:498) 位于org.junit.runners.model.FrameworkMethod$1.runReflectVeCall(FrameworkMethod.java:50) 位于org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) 位于org.junit.runners.model.FrameworkMethod.invokeeexplosive(FrameworkMethod.java:47) 位于org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) 位于org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26) 位于org.junit.internal.runners.statements.runafter.evaluate(runafter.java:27) 位于org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) 位于org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) 位于org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) 位于org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) 位于org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) 位于org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) 访问org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) 位于org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) 位于org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26) 位于org.junit.runners.ParentRunner.run(ParentRunner.java:363) 位于org.junit.runner.JUnitCore.run(JUnitCore.java:137) 位于com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68) 位于com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47) 在com.intellij public void insertProfileTest() throws JsonProcessingException { LOGGER.info(dbSession.getMetadata().getSchema().getClass(Profile.class).getProperty("name").toString()); LOGGER.info(dbSession.getMetadata().getSchema().getClass(Profile.class).getProperty("phone").toString()); LOGGER.info(dbSession.getMetadata().getSchema().getClass(Phone.class).getProperty("number").toString()); // Init Profile userProfile = new Profile("Jane Doe"); Phone homePhone = new Phone("212"); Phone cellPhone = new Phone("718"); userProfile.addPhone(homePhone); userProfile.addPhone(cellPhone); final String json = MAPPER.writeValueAsString(userProfile); LOGGER.info("Profile JSON:" + json); LOGGER.info("Phone Class :" + userProfile.getPhone().getClass().getName()); // DB final OVertex profileVertex = dbSession.newVertex("Profile"); profileVertex.setProperty("name", userProfile.getName()); profileVertex.setProperty("phone", userProfile.getPhone(), OType.EMBEDDEDLIST); // Fails to Save - // The field 'Profile.phone' has been declared as EMBEDDEDLIST but an incompatible type is used. Value: com.sample.profile.Phone@32f232a5 profileVertex.save(); } 14:11:00.124 [main] INFO com.sample.profile.ProfileTest - Initializing begin 14:11:01.187 [main] INFO com.sample.profile.ProfileTest - OrientDB [remote:localhost/test] Status: [OPEN] 14:11:01.191 [main] INFO com.sample.profile.ProfileTest - name (type=STRING) 14:11:01.192 [main] INFO com.sample.profile.ProfileTest - phone (type=EMBEDDEDLIST) 14:11:01.192 [main] INFO com.sample.profile.ProfileTest - number (type=STRING) 14:11:01.233 [main] INFO com.sample.profile.ProfileTest - Profile JSON:{"name":"Jane Doe1","phone":[{"number":"212"},{"number":"718"}]} 14:11:01.234 [main] INFO com.sample.profile.ProfileTest - Phone Class :java.util.ArrayList Jul 12, 2018 2:11:01 PM com.orientechnologies.common.log.OLogManager log INFO: Orient Engine is shutting down... com.orientechnologies.orient.core.exception.OValidationException: The field 'Profile.phone' has been declared as EMBEDDEDLIST but an incompatible type is used. Value: Phone{number:212} DB name="test" Error Code="4" at com.orientechnologies.orient.core.record.impl.ODocument.validateEmbedded(ODocument.java:814) at com.orientechnologies.orient.core.record.impl.ODocument.validateField(ODocument.java:601) at com.orientechnologies.orient.core.record.impl.ODocument.validate(ODocument.java:2365) at com.orientechnologies.orient.core.db.document.ODatabaseDocumentAbstract.saveInternal(ODatabaseDocumentAbstract.java:2057) at com.orientechnologies.orient.core.db.document.ODatabaseDocumentAbstract.save(ODatabaseDocumentAbstract.java:2042) at com.orientechnologies.orient.core.db.document.ODatabaseDocumentAbstract.save(ODatabaseDocumentAbstract.java:84) at com.orientechnologies.orient.core.record.impl.ODocument.save(ODocument.java:2109) at com.orientechnologies.orient.core.record.impl.ODocument.save(ODocument.java:2100) at com.orientechnologies.orient.core.record.impl.ODocument.save(ODocument.java:63) at com.sample.profile.ProfileTest.insertProfileTest(ProfileTest.java:98) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26) at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.junit.runner.JUnitCore.run(JUnitCore.java:137) at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68) at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47) at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242) at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70) package com.sample.profile; public class Phone { private String number; public Phone() { } public Phone(String number) { this.number = number; } public String getNumber() { return number; } public void setNumber(String number) { this.number = number; } @Override public String toString() { return "Phone{" + "number:" + number + '}'; } } package com.sample.profile; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; public class Profile { private String name; private Collection phone; public Profile() { } public Profile(String name) { this.name = name; } public Profile(String name, Collection phone) { this.name = name; this.phone = phone; } public void addPhone(Phone phoneNumber) { if (this.phone == null) { this.phone = new ArrayList(); } this.phone.add(phoneNumber); } public String getName() { return name; } public void setName(String name) { this.name = name; } public Collection getPhone() { return phone; } public void setPhone(Collection phone) { this.phone = phone; } @Override public String toString() { return "Profile{" + "name='" + name + '\'' + ", phone=" + Arrays.toString(phone.toArray()) + '}'; } } public void insertProfileTest() throws JsonProcessingException { LOGGER.info(dbSession.getMetadata().getSchema().getClass(Profile.class).getProperty("name").toString()); LOGGER.info(dbSession.getMetadata().getSchema().getClass(Profile.class).getProperty("phone").toString()); LOGGER.info(dbSession.getMetadata().getSchema().getClass(Phone.class).getProperty("number").toString()); // Init Profile userProfile = new Profile("Jane Doe"); Phone homePhone = new Phone("212"); Phone cellPhone = new Phone("718"); userProfile.addPhone(homePhone); userProfile.addPhone(cellPhone); final String json = MAPPER.writeValueAsString(userProfile); LOGGER.info("Profile JSON:" + json); LOGGER.info("Phone Class :" + userProfile.getPhone().getClass().getName()); // DB List phoneVertexList = new ArrayList(); for (Phone phone: userProfile.getPhone()) { final OVertex phoneVertex = dbSession.newVertex("Phone"); phoneVertex.setProperty("number", phone.getNumber()); phoneVertexList.add(phoneVertex); } final OVertex profileVertex = dbSession.newVertex("Profile"); profileVertex.setProperty("name", userProfile.getName()); profileVertex.setProperty("phone", phoneVertexList, OType.EMBEDDEDLIST); profileVertex.save(); } select * from Profile +----+-----+-------+--------+-------------------------------------+ |# |@RID |@CLASS |name |phone | +----+-----+-------+--------+-------------------------------------+ |0 |#41:0|Profile|Jane Doe|[Phone{number:212},Phone{number:718}]| +----+-----+-------+--------+-------------------------------------+ select * from Phone +----+-----+------+------+ |# |@RID |@CLASS|number| +----+-----+------+------+ |0 |#33:0|Phone |212 | |1 |#34:0|Phone |718 | +----+-----+------+------+