3

After upgrading from Springboot 2.6.14 to 2.7.9, I get the following errors in my integration tests. I have changed nothing apart from the spring boot version. It is not obvious to me why Table "DOCUMENT" not found;, this table does exist:

[INFO] Running com.trex.integration.tests.RepositoriesIT
[ERROR] Tests run: 2, Failures: 0, Errors: 2, Skipped: 0, Time elapsed: 0.071 s <<< FAILURE! - in com.trex.integration.tests.RepositoriesIT

[ERROR] testPageComponent  Time elapsed: 0.064 s  <<< ERROR!

com.trex.application.services.exception.AsyncPreProcessingServiceException: org.springframework.dao.InvalidDataAccessResourceUsageException: could not prepare statement; SQL [select documentda0_.id as id1_2_0_, documentda0_.company_country as company_2_2_0_, documentda0_.company_currency as company_3_2_0_, documentda0_.company_date_format as company_4_2_0_, documentda0_.created_utc as created_5_2_0_, documentda0_.labeled as labeled6_2_0_, documentda0_.labeled_at as labeled_7_2_0_, documentda0_.line_items as line_ite8_2_0_, documentda0_.batch_only as tech_onl9_2_0_, documentda0_.vat_registered_company as vat_reg10_2_0_, documentda0_.vde_document_id as vde_doc11_2_0_, documentda0_.workflow as workflo12_2_0_ from document documentda0_ where documentda0_.id=?]; nested exception is org.hibernate.exception.SQLGrammarException: could not prepare statement
        at com.trex.integration.tests.RepositoriesIT.testPageComponent(RepositoriesIT.java:153)


Caused by: org.springframework.dao.InvalidDataAccessResourceUsageException: could not prepare statement; SQL [select documentda0_.id as id1_2_0_, documentda0_.company_country as company_2_2_0_, documentda0_.company_currency as company_3_2_0_, documentda0_.company_date_format as company_4_2_0_, documentda0_.created_utc as created_5_2_0_, documentda0_.labeled as labeled6_2_0_, documentda0_.labeled_at as labeled_7_2_0_, documentda0_.line_items as line_ite8_2_0_, documentda0_.batch_only as tech_onl9_2_0_, documentda0_.vat_registered_company as vat_reg10_2_0_, documentda0_.vde_document_id as vde_doc11_2_0_, documentda0_.workflow as workflo12_2_0_ from document documentda0_ where documentda0_.id=?]; nested exception is org.hibernate.exception.SQLGrammarException: could not prepare statement
        at com.trex.integration.tests.RepositoriesIT.testPageComponent(RepositoriesIT.java:153)


Caused by: org.hibernate.exception.SQLGrammarException: could not prepare statement
        at com.trex.integration.tests.RepositoriesIT.testPageComponent(RepositoriesIT.java:153)


Caused by: org.h2.jdbc.JdbcSQLSyntaxErrorException:
Table "DOCUMENT" not found; SQL statement:
select documentda0_.id as id1_2_0_, documentda0_.company_country as company_2_2_0_, documentda0_.company_currency as company_3_2_0_, documentda0_.company_date_format as company_4_2_0_, documentda0_.created_utc as created_5_2_0_, documentda0_.labeled as labeled6_2_0_, documentda0_.labeled_at as labeled_7_2_0_, documentda0_.line_items as line_ite8_2_0_, documentda0_.batch_only as tech_onl9_2_0_, documentda0_.vat_registered_company as vat_reg10_2_0_, documentda0_.vde_document_id as vde_doc11_2_0_, documentda0_.workflow as workflo12_2_0_ from document documentda0_ where documentda0_.id=? [42102-214]
        at com.trex.integration.tests.RepositoriesIT.testPageComponent(RepositoriesIT.java:153)
  • If a table doesn't exist during the integration test, could be that the setup is not correct. Could be that the init script or whatever it creates the tables is not being executed or there is some race condition between the schema creation and tests. Could you add more details about how you are doing that? – Gastón Schabas May 11 '23 at 14:01
  • Does this only happen in this specific test or all the tests are failing because of a table doesn't exist – Gastón Schabas May 11 '23 at 14:03
  • 1
    I have made a change to my dao `@Column(columnDefinition = "TINYINT(1)")` to `@Column(columnDefinition = "TINYINT")` and this appears to have solved this problem. I took inspiration from this post: https://stackoverflow.com/questions/70695039/org-h2-jdbc-jdbcsqlsyntaxerrorexception-after-h2-version-upgrade – gravitypulling May 11 '23 at 14:18

2 Answers2

0

That issue was cause by spring boot is upgrading the h2 version to 2.x.x at the same time. I guess you could fix this problem by adding code in build.gradle such like runtimeOnly 'com.h2database:h2:1.4.200' to force it using the old version. I fix my one in this way.

Referencing to this question here. org.h2.jdbc.JdbcSQLSyntaxErrorException after H2 version upgrade

Ruka
  • 1
0

I have also got similar exception when update H2 from 1.4.xxx to 2.1.xxx. I got SQLGrammarException due to having native queries with [,] brackets in the query. After removing [], I was able to run successfully.

ctw_87
  • 1
  • 1
  • 3