Hi Jens,

The foreign key for child2 is not generated (note that this fk is a bit
> funky, since it only references part of the parent pk).


But why would you do that? I mean, GENERATED BY DEFAULT is by no means a
unique constraint. There could be duplicate id values in the parent table.
Things would probably work if you added a UNIQUE constraint. Or better yet,
add the partition_id also to child2, because after all, the key is
composite, so why not fix the schema?

On Wed, Sep 8, 2021 at 11:03 AM Jens Teglhus Møller <j...@mostlyharmless.dk>
wrote:

> Hi
>
> While trying to setup partitioned tables, I have noticed that the code
> generator seem to have a bug or feature where it does not alway generate
> all the foreign keys.
>
> When running the code generator on the following H2 database:
>
> create table parent (
>   id int generated by default as identity,
>   partition_id tinyint not null,
>   constraint pk_parent primary key (id, partition_id)
> );
>
> create table child1 (
>   id int generated by default as identity,
>   parent_id int not null,
>   partition_id tinyint not null,
>   constraint pk_child1 primary key (id),
>   constraint fk_child1_parent foreign key (parent_id, partition_id)
> references parent (id, partition_id)
> );
>
> create table child2 (
>   id int generated by default as identity,
>   parent_id int not null,
>   constraint pk_child2 primary key (id),
>   -- this fk does not cover the parents pk
>   constraint fk_child2_parent foreign key (parent_id) references parent
> (id)
> );
>
> The foreign key for child2 is not generated (note that this fk is a bit
> funky, since it only references part of the parent pk).
>
> The only generator log output regarding foreign keys is this:
>
> [INFO] Adding foreign key       : FK_CHILD1_PARENT
> (PUBLIC.CHILD1.PARENT_ID) referencing PK_PARENT (PUBLIC.PARENT.ID)
> [INFO] Adding foreign key       : FK_CHILD1_PARENT
> (PUBLIC.CHILD1.PARTITION_ID) referencing PK_PARENT
> (PUBLIC.PARENT.PARTITION_ID)
>
> I can push an example to github or supply generator log. I tested with
> jooq v1.15.2 and initially discovered it on v3.14.13.
>
> Best regards Jens
>
> --
> You received this message because you are subscribed to the Google Groups
> "jOOQ User Group" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to jooq-user+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/jooq-user/bd40cd8d-201a-404b-88db-e7bfa262a3e7n%40googlegroups.com
> <https://groups.google.com/d/msgid/jooq-user/bd40cd8d-201a-404b-88db-e7bfa262a3e7n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups "jOOQ 
User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to jooq-user+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jooq-user/CAB4ELO5dr18%2BsokDLO97b6zb3MwCdRjXOXniWm%2BoV_FZPDC-3A%40mail.gmail.com.

Reply via email to