Create multiple tables for one class in ORMLite

妖精的绣舞 提交于 2019-12-05 05:23:57

The big question here is what do you mean by "dynamic". If you mean that you need to create these module Orders on the fly and you don't know their names beforehand then I believe a module-name field is the an efficient way to do this. To create a table for each type of order seems like premature optimization to me -- complexity without good reason.

That said, you can accomplish dynamic classes by instantiating a DatabaseTableConfig for each table and defining the class programmatically.

If you don't really mean dynamic, then the easiest way to accomplish putting each module Order in its own table would be with subclasses.

You could have:

@DatabaseTable
public class FooOrder extends Order {
    // fields will be gotten from Order
}

@DatabaseTable
public class BarOrder extends Order {
    // fields will be gotten from Order
}

The fields from Order will be in each of the fooorder and barorder tables.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!