Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Javers doesn't work properly with H2 2.0.204 version (Invalid SQL syntax for the Sequence) #1168

Closed
pziobron opened this issue Jan 3, 2022 · 2 comments
Labels

Comments

@pziobron
Copy link

pziobron commented Jan 3, 2022

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;

@bartoszwalacik
Copy link
Member

@pziobron sorry but I cant help you if you do not provide a failing test case. This is an OSS project.
See https://github.com/javers/javers/blob/master/CONTRIBUTING.md#guidelines-for-bug-reporting

jamesmudd added a commit to jamesmudd/javers that referenced this issue Apr 5, 2022
This reproduces the bug in javers#1168 by updating H2 to 2.1.210 which is good any was as earlier versions have known exploits https://mvnrepository.com/artifact/com.h2database/h2.

As recommended in H2 migration to v2 docs http://www.h2database.com/html/migration-to-v2.html this switches to sequence value expression https://h2database.com/html/grammar.html#sequence_value_expression

This is backwards compatible with H2 v1
jamesmudd added a commit to jamesmudd/javers that referenced this issue May 24, 2022
This reproduces the bug in javers#1168 by updating H2 to 2.1.210 which is good any was as earlier versions have known exploits https://mvnrepository.com/artifact/com.h2database/h2.
@bartoszwalacik
Copy link
Member

fixed in 6.8.1

bartoszwalacik pushed a commit that referenced this issue Jul 16, 2023
This reproduces the bug in #1168 by updating H2 to 2.1.210 which is good any was as earlier versions have known exploits https://mvnrepository.com/artifact/com.h2database/h2.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants