Hi Robert,

There's no configuration for that, but you could define your own
PkGenerator easily. Here's how to do it if you are using MySQL:

ServerModule.contributePkGenerators(binder)
        .put(MySQLAdapter.class.getName(), MyPkGenerator.class)

And in the custom PK generator you'll need to redefine all methods with the
table name hardcoded (and you need to use), something like this:

public class MyPkGenerator extends MySQLPkGenerator {
    ...
    @Override
    protected String pkSelectString(String entName) {
        return "SELECT NEXT_ID FROM eo_pk_table WHERE TABLE_NAME = '" +
entName + '\'';
    }
    ...
}

Also judging by the table name you are converting from the WebObjects, and
if you'll need to keep Cayenne and WebObjects together you'll probably need
to sync Pk generation logic, not only the table name.

As for the Modeler, I don't think there's a simple way to do this. But if
you are trying to use Modeler as an SQL generator, it's not generally
recommended, it's primarily for dev purposes only.

On Thu, May 1, 2025 at 12:29 AM Robert A. Decker
<dec...@robdecker.com.invalid> wrote:

> I'm trying to set the name of the auto_pk_support table to be eo_pk_table
> instead.
>
> Is it possible to do this in code, similar to below with the
> addModule/ServerModule section (which doesn't work because the key isn't
> correct). I don't see anything I can use here:
>
> https://cayenne.apache.org/docs/4.1/cayenne-guide/#appendix-a-configuration-properties
>
> Also, is it possible to do in the modeller as well?
>
> thanks,
> Rob
>
>
> cayenneRuntime = ServerRuntime.builder()
>         .addConfig("cayenne-project.xml")
>         .addModule(binder ->
>                 ServerModule.contributeProperties(binder)
>                         .put("cayenne.PkGenerator.GeneratedKeyTableName",
> "eo_pk_table"))
>         .dataSource(DataSourceBuilder
>                 .url("jdbc:mysql://
> 127.0.0.1:3306/sms?useSSL=false&serverTimezone=UTC")
>                 .driver("com.mysql.cj.jdbc.Driver")
>                 .userName("sms")
>                 .password("").build())
>                 .build();
>
>
>
>

-- 
Best regards,
Nikita Timofeev

Reply via email to