I was trying to add an field to my entity as a CLOB. When using the JHipster CLI it was no problem to add it.
Now, when i trying to start my application i get the following validation error from liquibase:
liquibase.exception.ValidationFailedException: Validation Failed:
1 change sets check sum
config/liquibase/changelog/20170221193921_xxxxxxxx.xml::20170221193921-1::jhipster was: 7:d8b3f42d8d4d523c7b14f93b4c7657c7 but is now: 7:a2a365179a0d231c2771ebd79f51b1fc
i also tried the following:
./mvnw liquibase:clearCheckSums
The result was BUILD SUCCESS
.
i also tried ./mvnw liquibase:update and updateSQL, same result.
Can anyone tell me what my problem is with JHipster?
When we use liquibase all entity changes that happen later should be captured as separate changelogs(For eg. altering a table like adding a new column). Jhipster cli always seems to overwrite the entities(whichever changed) corresponding liquibase files(usually of the pattern 'config/liquibase/changelog/20180607110114_added_entity_Employee.xml'
). Therefore the entities liquibase file's checksum changes as it has new content now. And in your database, there is a table called DATABASECHANGELOG
which stores which all changeLogs were applied and this has checksum data.
Now when you start your application you will get error because your latest liquibase changeLog of modified entity's checksum is different from the last time(database will have a checksum for this liquibase file for previous verison) you ran.
mvn liquibase:clearCheckSums
is not the right approach most of the time unless needed. This actually clears all checksums in the database. You lose track of the changes that had happened which is usually not intended. These features of liquibase makes sense for eg like when you want to rollback the new changes you have applied. If you clear checksums and run the application it will compute new checksums you lose the track and can get you into trouble if not enough attention is paid.
Proper solution:
entity sub-generator
or jdl import
or manual changes to your entities directly
.'.._added_entity_...'
. For eg. 'config/liquibase/changelog/20180607110114_added_entity_Employee.xml'
.mvn liquibase:diff
. This will generate a changeLog file. Check it manually once and add it to liquibase's master.xml
file. Adding to master file is must as liquibase refers to this file for all changeLogs.To summarize, jhipster cli overwrites the entities liquibase files. Revert them and run mvn liquibase:diff
to capture the new changes to the entites in a new changeLog instead of overwriting the previously generated liquibase file. We can see that checksum error is resolved and also database changes are captured in liquibase as well.
References:
- How to deal with liquibase and Jhipster database updates.
Check heading with Database updates