Re: JdbcPkGenerator.pkCacheSize
Andrus Adamchik <[email protected]> Thu, 12 Feb 2026 14:07:29 -0500
| Newsgroups | gmane.comp.java.cayenne.user |
|---|---|
| Message-ID | <[email protected]> |
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...=20
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.=20
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.=20
Andrus
> On Feb 11, 2026, at 11:41=E2=80=AFAM, Robert A. Decker =
<[email protected]> wrote:
>=20
> 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.
>=20
> Rob
>=20
>> On 11 Feb 2026, at 15:53, Robert A. Decker <[email protected]> =
wrote:
>>=20
>> I'm on 4.2.1
>>=20
>> 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.
>>=20
>> 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.
>>=20
>> 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).
>>=20
>> 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?
>>=20
>> Rob
>=20
>=20