Hi Rob,

>> There seems to be some bugginess between JdbcPkGenerator and 
>> MySQLPkGenerator, where JdbcPkGenerator will generate a batch of pks but 
>> MySQLPkGenerator only increments the value in the pk cache table by 1 
>> instead of by 20 or whatever the cache is. This happens when I override 
>> MySQLPkGenerator.getLongPrimaryKey in my own pk generator, but I don't see 
>> anything in MySQLPkGenerator.getLongPrimaryKey where it's supposed to update 
>> the pk table by the cache size... 


I don't see any visible issues with MySQLPkGenerator. The default is 20, and it 
is applied via JdbcPkGenerator.pkUpdateString(..). Likely, you do not use 
"pkUpdateString(..)" in your overridden method, so it is ignored.

> I ended up just setting pkCacheSize in my pkgenerator constructor. 

Yep, that's how it should be done for custom generators.

FWIW, while I have very large projects on MySQL, I never use the PK generator. 
All affected tables are modeled using AUTO_INCREMENT with a matching "Database 
Generated" PK strategy on the Cayenne side:

CREATE TABLE table (
     id MEDIUMINT NOT NULL AUTO_INCREMENT,
     name CHAR(30) NOT NULL,
     PRIMARY KEY (id)
)

The DB itself takes care of setting unique PKs, and Cayenne simply reads it on 
insert. No need for special tables or PK cache strategies. 

Andrus



> On Feb 11, 2026, at 11:41 AM, Robert A. Decker <[email protected]> wrote:
> 
> I ended up just setting pkCacheSize in my pkgenerator constructor. It 
> actually makes more sense there than as a configuration value because it can 
> never use the cache because it just doesn't work.
> 
> Rob
> 
>> On 11 Feb 2026, at 15:53, Robert A. Decker <[email protected]> wrote:
>> 
>> I'm on 4.2.1
>> 
>> There seems to be some bugginess between JdbcPkGenerator and 
>> MySQLPkGenerator, where JdbcPkGenerator will generate a batch of pks but 
>> MySQLPkGenerator only increments the value in the pk cache table by 1 
>> instead of by 20 or whatever the cache is. This happens when I override 
>> MySQLPkGenerator.getLongPrimaryKey in my own pk generator, but I don't see 
>> anything in MySQLPkGenerator.getLongPrimaryKey where it's supposed to update 
>> the pk table by the cache size... I pretty much just copied the code from 
>> MySQLPkGenerator.getLongPrimaryKey so that I could change the table name.
>> 
>> Anyway, I could be completely wrong about the bugginess - I haven't 
>> confirmed it by running code without my subclass and I'm only going by what 
>> I see in the source code.
>> 
>> What I really need to know is how I can set the JdbcPkGenerator.pkCacheSize 
>> value to 1 (or 0) so that I don't have any caching of pks (I have multiple 
>> systems/codebases using the same database).
>> 
>> I don't see any way to do it in the DataSourceBuilder while building the 
>> cayenne runtime. Do I have to do it in my pkgenerator subclass?
>> 
>> Rob
> 
> 

Reply via email to