我想使用 DAO 将生成的 Pojo 添加到数据库。但我收到异常并且不知道如何解决它。
我尝试在每个表前面添加一个 Public.Troop 。
将部队插入到 DAO 用法中:
TroopDao dao = new TroopDao(new DefaultConfiguration().set(SQLDialect.SQLITE).set(database.getConnection()));
Troop initial = new Troop(1, 100, 120, 120.2, 11.2, 12.0, 13.0, 6245.0, 1534.0, 1364.0, 121235.3, 125.3, 51.3);
dao.insert(initial);
使用的数据库文件:
CREATE TABLE IF NOT EXISTS TROOP(
id INTEGER PRIMARY KEY AUTOINCREMENT,
current_health INTEGER NOT NULL,
max_health INTEGER NOT NULL,
pos_x DOUBLE NOT NULL,
pos_y DOUBLE NOT NULL,
normal_speed DOUBLE NOT NULL,
street_speed DOUBLE NOT NULL,
difficult_terrain_speed DOUBLE NOT NULL,
close_combat_range DOUBLE NOT NULL,
ranged_combat_range DOUBLE NOT NULL,
normal_view_distance DOUBLE NOT NULL,
disadvantaged_view_distance DOUBLE NOT NULL,
advantaged_view_distance DOUBLE NOT NULL
);
CREATE TABLE IF NOT EXISTS ARMY(
id INTEGER,
hq INTEGER,
troop INTEGER,
FOREIGN KEY(hq) REFERENCES TROOP(id),
FOREIGN KEY(troop) REFERENCES TROOP(id),
UNIQUE(hq, troop),
PRIMARY KEY (id, hq, troop)
);
JOOQ一代,我也尝试过unqualifiedSchema = main:
Configuration configuration = new Configuration()
.withGenerator(new Generator()
.withDatabase(new Database()
.withName("org.jooq.meta.extensions.ddl.DDLDatabase")
.withIncludes("ARMY | TROOP")
.withOutputSchemaToDefault(Boolean.TRUE)
.withProperties(new Property()
.withKey("unqualifiedSchema")
.withValue("none"),
new Property()
.withKey("scripts")
浮云间
相关分类