我已经编写了一个代码来通过apache metamodel创建一些表:

dataContext.executeUpdate(new UpdateScript() {
        @Override
        public void run(UpdateCallback updateCallback) {
            updateCallback.createTable(schema, "aTable").withColumn("id").ofType(ColumnType.INTEGER)
            .withColumn("anotherTableId").ofType(ColumnType.INTEGER).execute();
            updateCallback.createTable(schema, "anotherTable").withColumn("id").ofType(ColumnType.INTEGER).execute();
        }
}


如何添加这些表之间的关系?

最佳答案

您可以尝试:

dataContext.executeUpdate(new UpdateScript() {
        @Override
        public void run(UpdateCallback updateCallback) {
            Table aTable = updateCallback.createTable(schema, "aTable")
                .withColumn("id").ofType(ColumnType.INTEGER)
                .withColumn("anotherTableId").ofType(ColumnType.INTEGER).execute();
            Table anotherTable = updateCallback.createTable(schema, "anotherTable")
                .withColumn("id").ofType(ColumnType.INTEGER).execute();

            MutableRelationship.createRelationship(
               anotherTable.getColumnByName("id"),
               aTable.getColumnByName("anotherTableId"));
        }
}

10-06 13:57