Table.rename() does not seem to function as advertised in the documentation

52 views
Skip to first unread message

Alex

unread,
Nov 11, 2023, 11:58:27 AM11/11/23
to jOOQ User Group
Hello,

I have a database that contains several hundred tables with the same structure, just different names. Reading through the documentation, using Table.rename(Name) seems to be most appropriate for my querying needs.

Unfortunately, the example code on https://www.jooq.org/doc/latest/manual/code-generation/codegen-advanced/codegen-config-generate/codegen-covariant-overrides/codegen-covariant-overrides-rename/ does not appear to be valid. I want to be able to do exactly what that example is doing (take a generated table, change the table name that it is associated with, and still be able to use the generated fields to produce a valid query).

I am pretty new to jOOQ, so it is possible I am misunderstanding the intent of rename().

Thanks,
Alex

Lukas Eder

unread,
Nov 13, 2023, 3:10:31 AM11/13/23
to jooq...@googlegroups.com
Hi Alex,

I've just tried this:

TBook b = T_BOOK.rename("b");
System.out.println(
    ctx.select(b.ID).from(b)
);

And it prints the expected:

select "public"."b"."id"
from "public"."b"

So, you're probably thinking of something specific that didn't work for you?

Best Regards,
Lukas

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/jooq-user/dcec73a5-ca53-43a8-9b49-abfd4ec9e052n%40googlegroups.com.

Alex

unread,
Nov 13, 2023, 6:58:53 AM11/13/23
to jOOQ User Group
In my case, I am trying to do:

AuditTable a = AuditTable.AUDITTABLE.rename("a");
// Operate with a.ID

AuditTable is code generated and extends TableImpl<AuditTableRecord>.
AuditTable.AUDITTABLE is the static member that returns "new AuditTable()"

The IDE is saying that AuditTable.AUDITTABLE.rename("a") is returning Table<AuditTableRecord>, not AuditTable.

Is the generated code for TBook and T_BOOK somewhere I can look at? I tried searching through the github repository and wasn't able to find it.

Lukas Eder

unread,
Nov 13, 2023, 7:30:27 AM11/13/23
to jooq...@googlegroups.com
Well, https://github.com/jOOQ/jOOQ/issues/13336 was implemented in jOOQ 3.17, so I suggest upgrading then.

Alex

unread,
Nov 13, 2023, 7:37:37 AM11/13/23
to jOOQ User Group
Interesting. I just recently downloaded the trial of jOOQ 3.18.7. Is it possible that this functionality is missing from that?

Lukas Eder

unread,
Nov 13, 2023, 7:41:39 AM11/13/23
to jooq...@googlegroups.com
Check for these things:

- There's a code generation flag generateRenameMethodOverrides to turn this off (it's turned on by default, though)
- Check that you're really using that latest version, e.g. with mvn dependency:tree (especially if you're using third parties like Spring Boot or Etienne Studer's gradle plugin, which use hard-coded default versions, some version issues are to be expected)
- Check why the IDE is saying that. The generated code is local to your workspace, so you'll find it there.

Alex

unread,
Nov 13, 2023, 8:06:07 AM11/13/23
to jOOQ User Group
Thanks for the tips.

The startup logs for jooq do indicate "Thank you for using the 30 day free jOOQ 3.18.7 trial edition (Build date: 2023-11-02T04:38:15Z)"

I am able to see that code generation flag you mentioned in the current Generator.java, however when I have my IDE decompile the same file, it does not appear. In fact, a quick search seems to suggest that none of the changes to Generator.java after this version of the file are present.

Lukas Eder

unread,
Nov 13, 2023, 8:14:06 AM11/13/23
to jooq...@googlegroups.com
Are you also using the 3.18.7 version of the code generator?

Alex

unread,
Nov 13, 2023, 8:23:42 AM11/13/23
to jOOQ User Group
Yes. Here's the output from my codegen script:

08:22:25,114  INFO [org.jooq.Constants                                ] - Thank you for using the 30 day free jOOQ 3.18.7 trial edition (Build date: 2023-11-02T04:38:15Z)

Alex

unread,
Nov 13, 2023, 8:31:26 AM11/13/23
to jOOQ User Group
After responding, I realized I may not have answered your question. I can confirm that the codegen jar being used is jooq-codegen-3.18.7.jar which was downloaded from the website as the free trial for the pro version.

Lukas Eder

unread,
Nov 13, 2023, 8:31:33 AM11/13/23
to jooq...@googlegroups.com
Can you try using our MCVE templates?

As you can see here, the override is being generated, for example for SQL Server:

I'm not sure what else could be the problem...

Lukas Eder

unread,
Nov 13, 2023, 8:35:01 AM11/13/23
to jooq...@googlegroups.com
Alternatively, instead of trying the MCVE template, can you post your complete code generation configuration here

Rob Sargent

unread,
Nov 13, 2023, 8:55:47 AM11/13/23
to jooq...@googlegroups.com
On 11/13/23 06:35, Lukas Eder wrote:
> Alternatively, instead of trying the MCVE template, can you post your
> complete code generation configuration here
>

Doesn't this have the smell of multiple jOOQ installations.  Perhaps we
should see the maven file or the runtime classpath?

Alex

unread,
Nov 13, 2023, 9:10:41 AM11/13/23
to jOOQ User Group
Aha! I figured it out. I had withInstanceFields set to false for some reason, which was causing the codegen to not generate the overrides.

Lukas Eder

unread,
Nov 13, 2023, 9:29:23 AM11/13/23
to jooq...@googlegroups.com
Yes, the overrides are pointless when this legacy flag is turned on.

--
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.
Reply all
Reply to author
Forward
0 new messages