我正在尝试通过ORMLite生成SQLite数据库:
Main.java:
connectionSource = new JdbcConnectionSource("jdbc:sqlite:testvault.db");
TableUtils.createTableIfNotExists(connectionSource, Account.class);
TableUtils.createTableIfNotExists(connectionSource, Order.class);
Account.java:
@DatabaseTable
public class Account {
@DatabaseField(generatedId = true)
private Integer id;
@DatabaseField(canBeNull = false)
private String name;
public Account() {
}
}
Order.java:
@DatabaseTable
public class Order {
@DatabaseField(generatedId = true)
private Integer id;
@DatabaseField(foreign = true, foreignAutoRefresh = true, foreignAutoCreate = true)
private Account account;
public Order() {
}
}
并创建带有以下内容的表格:
CREATE TABLE `order` (
`id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
`account_id` INTEGER NOT NULL
);
位置:
CREATE TABLE `order` (
`id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
`account_id` INTEGER NOT NULL,
FOREIGN KEY(`account_id`) REFERENCES `account`(`id`)
);
我该怎么做才能使ORMLite生成约束?