使用嵌入式类型时,级联保存在 OrientDB 文档 API 上

Cascade save on OrientDB Document API when using embedded types

给出以下测试:

    // 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:<1> but was:<0> at org.junit.Assert.fail(Assert.java:88) at org.junit.Assert.failNotEquals(Assert.java:834) at org.junit.Assert.assertEquals(Assert.java:645) at org.junit.Assert.assertEquals(Assert.java:631) at foo.orientdb.dataaccessapi.StoreJSonIT.testSchemaFull(StoreJSonIT.java:68)

为什么会失败?

属性 CAR 和 DRIVER 创建为 嵌入列表 嵌入集 ,不应该单独保存在 mclarenF1Team 为嵌入文档做级联保存?

Embedded List/Set 表示您创建的文档将嵌入(保存)在父文档中而不是在他自己的 class/cluster.

如果您想实现该行为,您应该使用链接

看这里

http://orientdb.com/docs/2.1/Concepts.html#relationships