| Switching from Hibernate 5.3.7 to 5.4.1 some of our JUnit-Tests failed with the following message:
Caused by: org.hibernate.MappingException: The increment size of the [GA_NODEINFO_OID_SEQ] sequence is set to [50] in the entity mapping while the associated database sequence increment size is [1].
at org.hibernate.id.enhanced.SequenceStyleGenerator.configure(SequenceStyleGenerator.java:256)
at org.hibernate.id.factory.internal.DefaultIdentifierGeneratorFactory.createIdentifierGenerator(DefaultIdentifierGeneratorFactory.java:118)
... 91 more
But a quick look on the Oracle DB showed that the sequence GA_NODEINFO_OID_SEQ had the increment set to 50. So the message is clearly not right. Cause for this error is probably a bug in the heuristic to determine the increment of a sequence. In our case the problem is that the metadata for the sequence can not be determined, because the sequence is a synonym to a sequence in a different schema, i.e. the name of the current schema is not in the table all_sequences. In the SequenceStyleGenerator the schema name is therefore null
private Long getSequenceIncrementValue(JdbcEnvironment jdbcEnvironment, String sequenceName) {
return jdbcEnvironment.getExtractedDatabaseMetaData().getSequenceInformationList().stream().filter(
sequenceInformation -> {
Identifier catalog = sequenceInformation.getSequenceName().getCatalogName();
Identifier schema = sequenceInformation.getSequenceName().getSchemaName();
return sequenceName.equalsIgnoreCase( sequenceInformation.getSequenceName().getSequenceName().getText() ) &&
( catalog == null || catalog.equals( jdbcEnvironment.getCurrentCatalog() ) ) &&
( schema == null || schema.equals( jdbcEnvironment.getCurrentSchema() ) );
}
).map( SequenceInformation::getIncrementValue ).findFirst().orElse( null );
}
and the increment value is in consequence the value of the first sequence with the same sequence name. Unfortunately our test DB contains more than one schema with the same setup, so the sequence name is not unique within the DB and the increment has changed over time. So we get sometimes the wrong increment value from a sequence in a different schema. So in our case it would be correct to return an increment value only if sequence name and schema name (or catalog name) are matched. |