[英]JOOQ - getPrimaryKey(), getIdentity() returns null
使用这个:
System.out.println("PRIMARY KEY: " + DSL.table(DSL.name(tableName)).getPrimaryKey());
返回 null :/ (也试过 getIdentity())
在调用 getPrimaryKey 之前我执行所有查询:
CreateTableColumnStep table = ctx.createTable(tableName).column("id", INTEGER.identity(true));
table.constraints(DSL.constraint("pk_" + tableName).primaryKey("id"));
文本中的输出是:create table filetest(id integer primary key autoincrement not null, Meno varchar(21) null, Priezvisko varchar(24) null, Vek int null);
所以有'id'主键......不要明白。
也试过: ctx.meta(DSL.table("tableName")).getPrimaryKeys() 或 ctx.meta(DSL.tableByName("tableName")... 返回空列表
返回 null :/ (也试过 getIdentity())
当您调用DSL.table(Name)
,您正在即时创建表元数据。 您提供的唯一元数据是(限定的)表名。 您没有提供任何列信息,更不用说约束信息,因此您不能真正期望 jOOQ 神奇地“知道”某处应该有一个主键。
在调用 getPrimaryKey 之前我执行所有查询:
在查询主键之前创建同名表并不重要。 对于所有 jOOQ 所知,您创建的这个表元信息是一个带有名称且没有列/约束的表。
也试过: ctx.meta(DSL.table("tableName")).getPrimaryKeys() 或 ctx.meta(DSL.tableByName("tableName")... 返回空列表
我可以看到这看起来令人困惑。 与调用ctx.meta()
(这可能是您在这里需要的)然后为您的表查询ctx.meta(Table...)
, ctx.meta(Table...)
只是将参数表的元信息包装在org.jooq.Meta
而无需连接到数据库。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.