codegen does not generate properly self-referencing foreign key

114 views
Skip to first unread message

Julien Nicoulaud

unread,
Jul 1, 2013, 8:43:41 AM7/1/13
to jooq...@googlegroups.com
Hi all,

I have a table that looks like this (using H2):

CREATE TABLE IF NOT EXISTS STEP (
  DB_ID      IDENTITY AUTO_INCREMENT NOT NULL PRIMARY KEY,
  PARENT     BIGINT,
  CONSTRAINT STEP_PARENT_FK FOREIGN KEY (PARENT) REFERENCES STEP (DB_ID),
);

jOOQ codegen fails at generating code, with the following message:

     [WARN ] Foreign key mismatch     : STEP_PARENT_FK does not match its primary key! No code is generated for this key. See trac tickets #64 and #69
     [WARN ] Foreign key mismatch     : STEP_PARENT_FK does not match its primary key! No code is generated for this key. See trac tickets #64 and #69

It works fine for every other foreign key I have in the schema, that reference other tables. Am I missing something obvious ? I can't find trace of these tickets, jOOQ Trac seems to be closed.

Regards,
Julien

Lukas Eder

unread,
Jul 1, 2013, 9:02:45 AM7/1/13
to jooq...@googlegroups.com
Hello,

What jOOQ version are you using for this? I cannot reproduce these warnings with your DDL with jOOQ 3.1.
The Trac tickets were merged into GitHub using the same ticket IDs

Cheers
Lukas


2013/7/1 Julien Nicoulaud <julien.n...@gmail.com>

--
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+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Julien Nicoulaud

unread,
Jul 1, 2013, 9:38:24 AM7/1/13
to jooq...@googlegroups.com
Using jOOQ 2.6.4 (can't upgrade, at least for now).

The two tickets are:
 - #64: Code generation fails when foreign key references a unique key that is not the primary key
 - #69: Implement referential code generation for foreign keys that reference non-primary unique keys (closed without commits)

It seems similar to my case, but not exactly the same, since I'm referencing a primary key...

Julien


2013/7/1 Lukas Eder <lukas...@gmail.com>

--
You received this message because you are subscribed to a topic in the Google Groups "jOOQ User Group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jooq-user/fLMQ8UWxtt4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jooq-user+...@googlegroups.com.

Lukas Eder

unread,
Jul 2, 2013, 7:48:49 AM7/2/13
to jooq...@googlegroups.com
Hmm, I still cannot reproduce this issue, also with jOOQ 2.6.4.

Did you include the complete, relevant DDL? Or are there any other constraints (unique keys, foreign keys) involved with the STEP table? Note, there was a fix in jOOQ 3.0.0 related to multiple foreign key constraints defined on a single column:


2013/7/1 Julien Nicoulaud <julien.n...@gmail.com>

Julien Nicoulaud

unread,
Jul 2, 2013, 2:03:29 PM7/2/13
to jooq...@googlegroups.com
Yes,

I can confirm it was this issue, I had several constraints on the same column. I upgraded to 3.1 and gave up navigation methods ;)

Thanks for your help !

Cheers,
Julien

2013/7/2 Lukas Eder <lukas...@gmail.com>

Lukas Eder

unread,
Jul 2, 2013, 2:39:40 PM7/2/13
to jooq...@googlegroups.com
OK. Unfortunately, that issue was rather complex to fix, so a merge to 2.6 was not an option at the time.

I remember you tried convincing me to add the navigation methods again :-)

You know that you can still "navigate" foreign keys through fetchChild() and fetchParent() methods?

http://www.jooq.org/javadoc/latest/org/jooq/TableRecord.html#fetchParent(org.jooq.ForeignKey)

It is a bit more verbose, but also more precise, specifically because you can have several foreign keys on the same column

Cheers
Lukas

2013/7/2 Julien Nicoulaud <julien.n...@gmail.com>

Julien Nicoulaud

unread,
Jul 2, 2013, 3:17:19 PM7/2/13
to jooq...@googlegroups.com
Yes,

Now I know, that's why I finally upgraded to jOOQ 3.1. I didn't know at the time I tried to convince you to keep navigation methods :)

Thanks,
Julien
Reply all
Reply to author
Forward
0 new messages