Javers doesn't work properly with H2 2.0.204 version (Invalid SQL syntax for the Sequence)
Steps To Reproduce
Try to use Javers with the newest H2 (2.0.204) dependency.
Unfortunately, I do not have time to write a runnable test.
You will observe the following error:
com.hsbc.gecs.dtcswebapp.application.rest.advice.CustomResponseEntityExceptionHandler: The following Exception occured: org.javers.common.exception.JaversException: SQL_EXCEPTION: Column "JV_COMMIT_PK_SEQ.NEXTVAL" not found; SQL statement: SELECT jv_commit_pk_seq.nextval [42122-204] while executing sql: SELECT jv_commit_pk_seq.nextval at org.javers.repository.sql.session.PreparedStatementExecutor.wrapExceptionAndCall(PreparedStatementExecutor.java:128) at org.javers.repository.sql.session.PreparedStatementExecutor.<init>(PreparedStatementExecutor.java:27) at org.javers.repository.sql.session.Session.getOrCreatePreparedStatement(Session.java:120) at org.javers.repository.sql.session.Session.executeQueryForLong(Session.java:85) at org.javers.repository.sql.session.Sequence.nextValue(Sequence.java:27) at org.javers.repository.sql.session.KeyGenerator$SequenceAllocation.generateKey(KeyGenerator.java:42) at org.javers.repository.sql.session.Session.executeInsertAndGetSequence(Session.java:46) at org.javers.repository.sql.session.InsertBuilder.executeAndGetSequence(InsertBuilder.java:54) at org.javers.repository.sql.repositories.CommitMetadataRepository.save(CommitMetadataRepository.java:35) at org.javers.repository.sql.JaversSqlRepository.persist(JaversSqlRepository.java:86) at org.javers.repository.api.JaversExtendedRepository.persist(JaversExtendedRepository.java:154) at org.javers.core.JaversCore.persist(JaversCore.java:109) at org.javers.core.JaversCore.commit(JaversCore.java:90) at org.javers.spring.transactions.JaversTransactionalDecorator.commit(JaversTransactionalDecorator.java:68) at org.javers.spring.jpa.JaversTransactionalJpaDecorator.commit(JaversTransactionalJpaDecorator.java:50) at org.javers.spring.jpa.JaversTransactionalJpaDecorator$$FastClassBySpringCGLIB$$8b0feaeb.invoke(<generated>)
Javers' Version
6.5.3
Additional context
I've tested the fix and it works (JaversException is not raised any more) !
Modify the body of the getKeyGeneratorDefinition method in the H2 inner static class of the org.javers.repository.sql.session.Dialects class (in the javers-persistence-sql package) by replacing
this line:
return (SequenceDefinition) seqName -> seqName + ".nextval";
with:
return (SequenceDefinition) seqName -> "NEXT VALUE FOR " + seqName;
Javers doesn't work properly with H2 2.0.204 version (Invalid SQL syntax for the Sequence)
Steps To Reproduce
Try to use Javers with the newest H2 (2.0.204) dependency.
Unfortunately, I do not have time to write a runnable test.
You will observe the following error:
com.hsbc.gecs.dtcswebapp.application.rest.advice.CustomResponseEntityExceptionHandler: The following Exception occured: org.javers.common.exception.JaversException: SQL_EXCEPTION: Column "JV_COMMIT_PK_SEQ.NEXTVAL" not found; SQL statement: SELECT jv_commit_pk_seq.nextval [42122-204] while executing sql: SELECT jv_commit_pk_seq.nextval at org.javers.repository.sql.session.PreparedStatementExecutor.wrapExceptionAndCall(PreparedStatementExecutor.java:128) at org.javers.repository.sql.session.PreparedStatementExecutor.<init>(PreparedStatementExecutor.java:27) at org.javers.repository.sql.session.Session.getOrCreatePreparedStatement(Session.java:120) at org.javers.repository.sql.session.Session.executeQueryForLong(Session.java:85) at org.javers.repository.sql.session.Sequence.nextValue(Sequence.java:27) at org.javers.repository.sql.session.KeyGenerator$SequenceAllocation.generateKey(KeyGenerator.java:42) at org.javers.repository.sql.session.Session.executeInsertAndGetSequence(Session.java:46) at org.javers.repository.sql.session.InsertBuilder.executeAndGetSequence(InsertBuilder.java:54) at org.javers.repository.sql.repositories.CommitMetadataRepository.save(CommitMetadataRepository.java:35) at org.javers.repository.sql.JaversSqlRepository.persist(JaversSqlRepository.java:86) at org.javers.repository.api.JaversExtendedRepository.persist(JaversExtendedRepository.java:154) at org.javers.core.JaversCore.persist(JaversCore.java:109) at org.javers.core.JaversCore.commit(JaversCore.java:90) at org.javers.spring.transactions.JaversTransactionalDecorator.commit(JaversTransactionalDecorator.java:68) at org.javers.spring.jpa.JaversTransactionalJpaDecorator.commit(JaversTransactionalJpaDecorator.java:50) at org.javers.spring.jpa.JaversTransactionalJpaDecorator$$FastClassBySpringCGLIB$$8b0feaeb.invoke(<generated>)Javers' Version
6.5.3
Additional context
I've tested the fix and it works (JaversException is not raised any more) !
Modify the body of the getKeyGeneratorDefinition method in the H2 inner static class of the org.javers.repository.sql.session.Dialects class (in the javers-persistence-sql package) by replacing
this line:
return (SequenceDefinition) seqName -> seqName + ".nextval";with:
return (SequenceDefinition) seqName -> "NEXT VALUE FOR " + seqName;