I think you found two problems at once. The first one with the docs that are just outdated and wrong. And the second one with the MySQLPkGenerator.longPkFromDatabase() method, where pkUpdateString() and pkSelectString() methods are called via `super` for some reason [1]. So it seams you'll need to redefine longPkFromDatabase() method completely to implement what you need.
[1] https://github.com/apache/cayenne/blob/e574e44bd026af341da5064404ca2c4559005f07/cayenne/src/main/java/org/apache/cayenne/dba/mysql/MySQLPkGenerator.java#L160-L175 On Fri, May 2, 2025 at 7:56 AM Robert A. Decker <dec...@robdecker.com.invalid> wrote: > I forgot to mention.... when it calls getLongPrimaryKey it throws the > exception: > SQLSyntaxErrorExceptio: Table 'sms.auto_pk_support' doesn't exist > > If it's meant to call the other overridden sql methods after that then I > won't know because the exception is thrown first. > > Looking at the docs: > JdbcPkGenerator.longPkFromDatabase(DataNode node, DbEntity entity) > doc says: "Subclasses that implement different primary key generation > solutions should override this method, not "generatePkForDbEntity". But > that method doesn't actually exist... > > Rob > > > > On 1 May 2025, at 22:41, Robert A. Decker <dec...@robdecker.com.INVALID> > wrote: > > > > thanks for getting me on the right track. > > > > I've confirmed that my custom pk generator is working because I overrode > the method: > > @Override > > protected long getLongPrimaryKey(Statement statement, String entityName) > throws SQLException { > > return super.getLongPrimaryKey(statement, entityName); > > } > > > > and I've confirmed in the debugger that that particular method is being > called in my custom pk generator when i create a new entity. > > > > However, the following two methods in my custom pk generator aren't > being called at all: > > @Override > > protected String pkUpdateString(String entName) { > > return "update EO_PK_TABLE SET PK = PK+1 where NAME = '" + entName + "'"; > > } > > > > @Override > > protected String pkSelectString(String entName) { > > return "SELECT PK FROM eo_pk_table WHERE NAME = '" + entName + "'"; > > } > > > > > > I think I can probably do everything I need to do in getLongPrimaryKey > if I need to, but it would be nice to use those two sql string methods. > > > > I'll work on it a bit more this weekend. > > > > Rob > > > > > >> On 1 May 2025, at 02:42, Nikita Timofeev <ntimof...@objectstyle.com> > wrote: > >> > >> 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 > > > > -- Best regards, Nikita Timofeev