在 JOOQ 生成器中禁用关系生成的后果是什么?

What are the consequences of disabling relation generation in the JOOQ generator?

我可以通过设置以下 configuration options:

来禁用 JOOQ 生成器中的身份、外键和唯一键生成
<generate>
  <!-- Primary key / foreign key relations should be generated and used.
       This is a prerequisite for various advanced features.
       Defaults to true -->
  <relations>false</relations>

尽管元模型中不存在 FK/UK 信息,但禁用这一代的后果究竟是什么? JOOQ 本身的哪些功能取决于此信息?

基本上,手册中有关 CRUD 的部分中记录的大部分功能对您来说将不可用:

http://www.jooq.org/doc/latest/manual/sql-execution/crud-with-updatablerecords/

主键

不了解主键,就没有UpdatableRecord。即,您将无法编写如下内容:

// This works:
MyTableRecord record =
DSL.using(configuration)
   .selectFrom(MY_TABLE)
   .where(MY_TABLE.ID.eq(1))
   .fetchOne();

// These won't work:
record.store();
record.update();
record.refresh();
record.delete();

// This will still work:
record.insert();

外键

外键信息目前仅在 jOOQ 中的少数地方使用,其中 navigation methods:

BookRecord book = DSL.using(configuration)
                     .selectFrom(BOOK).where(BOOK.ID.eq(1)).fetchOne();

// This won't work
AuthorRecord author = book.fetchParent(FK_BOOK_AUTHOR);

还计划增强代码生成器以生成此类导航方法 (#4210),这意味着以下内容将不起作用:

// This won't work
AuthorRecord author = book.fetchFkBookAuthor();

或者,合成 JOIN ON KEY 子句:

DSL.using(configuration)
   .select()
   .from(AUTHOR)
   .join(BOOK).onKey()
   .fetch();

根据约束信息的可用性,未来还会有其他功能,但普通SQL语句不受影响。