2

In my Spring-Boot project when:

  • javers.sqlSchemaManagementEnabled=true
    The Javers tables are created on the first execution (when the tables do not exist on the database) and the code runs as expected, however from the second execution onwards an exception is thrown describing that the tables cannot be created because them already exist. This is the situation that I cannot understand, isn't Javers supposed to know that the tables already exist and do not attempt to create the tables?

  • javers.sqlSchemaManagementEnabled=false
    If the tables where already created on the database, manually or executing the application with this option as 'true' at least once, the application executes as expected.

What am I supposed to do?

  1. Is there something wrong with my Spring-Boot configuration? The application was supposed to run with 'sqlSchemaManagementEnabled=true' even with the tables already created?
  2. I expected is to leave the 'sqlSchemaManagementEnabled=false' and create the tables manually?
Rodolfo
  • 149
  • 1
  • 9

2 Answers2

1

I had the same problem, when using other than public schema in PostgreSQL.

I solved it by switching to public schema, now it works correctly with javers.sqlSchemaManagementEnabled=true.

For other schemas, you should somehow specify the schema name in org.javers.repository.sql.schema.TableNameProvider

planky
  • 440
  • 1
  • 4
  • 16
  • 1
    Using properties explicitly worked for me, I wouldn't figure it out so easily though. Thank you. `javers.sqlSchema=` https://javers.org/documentation/spring-boot-integration/#javers-configuration-properties – bzani May 25 '21 at 14:57
0

If javers.sqlSchemaManagementEnabled=true, Javers creates SQL tables if they do not exists already.

It's checked here:

https://github.com/javers/javers/blob/master/javers-persistence-sql/src/main/java/org/javers/repository/sql/schema/JaversSchemaManager.java#L215

It's hard to say why it doesn't work in your case, try to debug this code using the latest Javers version.

Bartek Walacik
  • 3,386
  • 1
  • 9
  • 14
  • 1
    The tables are created as expected, however Javers keep trying to create them on future executions. – Rodolfo Jan 18 '19 at 11:45
  • javers tries to create tables only in the bootstrap phase, debug the code I have pointed – Bartek Walacik Jan 18 '19 at 15:52
  • Javers continuously tries to create tables that exist for me. I'm using the Spring Boot starter and I'm using default properties except for javers.sqlSchema=AUDIT. According to the stacktrace, it is returning `relationExists(...)` as false and so it is trying to create jv_commit again. – John Strickler May 18 '20 at 16:06
  • Hi, you are supposed to create a a Minimal, Reproducible Example (https://stackoverflow.com/help/minimal-reproducible-example), push it here https://github.com/javers/javers/tree/master/javers-core/src/test/groovy/org/javers/core/cases There are dockerized integration test for all supported databases – Bartek Walacik May 19 '20 at 09:23