java - Apache Metamodel How to add foreign keys while creating tables -
i've written code create tables 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(); } }
how can add relationship between these tables?
you try:
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")); } }
Comments
Post a Comment