Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

spring - jhipster liquibase validation error after modify entity

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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:

  1. Make changes to your entities using jhipster entity sub-generator or jdl import or manual changes to your entities directly.
  2. Now check if the entities corresponding liquibase file was changed or not. Usually name contains '.._added_entity_...' . For eg. 'config/liquibase/changelog/20180607110114_added_entity_Employee.xml'.
  3. Revert that file back to what it was in case it was overwritten. Git is helpful here for reverting.
  4. If you start the application now you will not get validation checksum error as checksum of the file matches.
  5. But the change we made to entity is not captured in liquibase. For this you have to run 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.
  6. If you run the application now, if the changeLogs were not applied, then liquibase will try to apply these new changes on the database.

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...