1

我编写了一个代码来通过 apache 元模型创建一些表:

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();
        }
}

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

4

1 回答 1

0

你可以试试:

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"));
        }
}
于 2016-11-13T17:34:27.903 回答