鉴于以下测试:
// setup
OClass driver = getDatabase().getMetadata().getSchema().createClass(DRIVER);
OClass car = getDatabase().getMetadata().getSchema().createClass(CAR);
car.createProperty(DRIVERS, OType.EMBEDDEDLIST, driver);
OClass team = getDatabase().getMetadata().getSchema().createClass(TEAM);
team.createProperty(CARS, OType.EMBEDDEDSET, car);
// exercise
ODocument alonso = new ODocument(DRIVER).field("name", "Fernando Alonso").field("nationality", "Spanish")
.field("yearOfBirth", 1981);
ODocument button = new ODocument(DRIVER).field("name", "Jenson Button").field("nationality", "british")
.field("yearOfBirth", 1980);
ODocument mp30 = new ODocument(CAR).field(DRIVERS, Arrays.asList(new ODocument[] { alonso, button }));
Set<ODocument> cars = new HashSet<>();
cars.add(mp30);
ODocument mclarenF1Team = new ODocument(TEAM).field(CARS, cars);
mclarenF1Team.save();
// verify
assertEquals(1, getDatabase().countClass(TEAM));
assertEquals(1, getDatabase().countClass(CAR));
assertEquals(2, getDatabase().countClass(DRIVER));
第二个断言失败:
java.lang.AssertionError:expected:&lt; 1&gt;但是:&lt; 0&gt; 在org.junit.Assert.fail(Assert.java:88) 在org.junit.Assert.failNotEquals(Assert.java:834) 在org.junit.Assert.assertEquals(Assert.java:645) 在org.junit.Assert.assertEquals(Assert.java:631) 在foo.orientdb.dataaccessapi.StoreJSonIT.testSchemaFull(StoreJSonIT.java:68)
为什么会失败?
属性CAR和DRIVER创建为嵌入列表和嵌入式集,不应单独保存在 mclarenF1Team 执行级联保存为嵌入式文档?
答案 0 :(得分:1)
嵌入式列表/集意味着您创建的文档将嵌入(保存)在父文档中,而不是嵌入到自己的类/集群中。
如果您想要实现该行为,则应使用链接
见这里