I notice that in MySQLPkGenerator.getLongPrimaryKey it does the select first, and then it does the update +1 for the pk.
Is this also the order that WebObjects does it? I have a 25-year-old project that is currently a mix of old java webobjects running the back-end engine, Ruby on Rails with React for the UI, spring-boot with cayenne for the replacement engine and also new features like spring-ai... In my Rails code I've been updating and then selecting. If WebObjects does it the other way around then we'll be skipping keys every now and then. No big deal, and I probably won't change anything because we've had 0 pk related bugs, but just curious. Rob > On 5 May 2025, at 13:47, Michael Gentry <blackn...@gmail.com> wrote: > > Opened a PR for this issue (CAY-2889). FWIW, Jira wouldn't allow me to > assign the issue to myself. > > On Fri, May 2, 2025 at 2:06 PM Michael Gentry <blackn...@gmail.com> wrote: > >> Hi Robert! >> >> You are correct that it should've called the methods in your class. I'll >> open a JIRA for the MySQLPkGenerator to remove the 'super` calls, but for >> now, you'll have to manually fix it in your subclass. >> >> Thanks for bringing this to our attention, >> mrg >> >> >> On Fri, May 2, 2025 at 10:29 AM Robert A. Decker >> <dec...@robdecker.com.invalid> wrote: >> >>> I'll try that next. It seemed logical to be able to just override those >>> methods in a subclass. But next, I'll copy/refactor the base class. I >>> didn't look at the cayenne source code - was hoping to avoid that. >>> >>> Rob >>> >>>> On 2 May 2025, at 06:49, Michael Gentry <blackn...@gmail.com> wrote: >>>> >>>> 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 >>>>> >>>>> >>> >>>