Hi Robert, I'm assuming you copied MySQLPkGenerator.java to a new PK Generator class and made changes.
MySQLPkGenerator::getLongPrimaryKey calls super.pkSelectString(entityName) and super.pkUpdateString(entityName), which are located in JdbcPkGenerator. If you didn't remove the 'super' calls in your new PK Generator class, it won't call your new methods. It'll use the ones in JdbcPkGenerator, so please check that. Thanks, mrg On Thu, May 1, 2025 at 11:42 PM 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 > >