I’m having a table which has a primary key which is generated with table generator:
@TableGenerator(name = “resourceIdGenerator”, table = “SEQUENCE”, pkColumnName = “NAME”, pkColumnValue = “resource_type_id”, valueColumnName = “NEXTID”, allocationSize = 1)
and it works fine.
However, I have another system(non-java) that modifies the same table from time-to-time by inserting new records into it. I’m wondering is it possible to update the values of this table generator of mine from another system that is not using JPA? Or the JPA maintains this by its own and it’s the only one which manages the tablegenerator table?
JPA can’t magically use a table and forbid anyone else to use it. If you use the same strategy in your other system as the one used by Hibernate to generate your IDs, there’s no reason it wouldn’t work.
Since the allocation size is 1, you probably just need to start a new transaction,
select for updatethe appropriate row of the sequence table, get its value and increment it by 1.