问题
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?
回答1:
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:
- Make changes to your entities using jhipster
entity sub-generator
orjdl import
ormanual changes to your entities directly
. - 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'
. - Revert that file back to what it was in case it was overwritten. Git is helpful here for reverting.
- If you start the application now you will not get validation checksum error as checksum of the file matches.
- 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'smaster.xml
file. Adding to master file is must as liquibase refers to this file for all changeLogs. - 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
回答2:
Try Executing the following query in your DB: UPDATE DATABASECHANGELOG SET MD5SUM = null WHERE ID='YOUR TABLE ID';
YOUR TABLE ID in this case seems to be = 20170221193921-1.
回答3:
When we add a column in Jhipster using the command jhpster entity xxxx
it is not added as a seperate changeset, instead the column is added in the existing change set for create table and as there is a change in the file new checksum is generated and on startup it is different from the DB so validation fails
<changeSet id="20181209164925-1" author="jhipster" >
<createTable tableName="xxxxxx">
<column name="id" type="bigint" autoIncrement="${autoIncrement}">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="xxxxx" type="integer">
<constraints nullable="true" />
</column>
<column name="xxxxx" type="integer">
<constraints nullable="true" />
</column>
<column name="xxxxxx" type="varchar(140)">
<constraints nullable="true" />
</column>
<column name="xxxx" type="bigint">
<constraints nullable="true" />
</column>
<!-- jhipster-needle-liquibase-add-column - JHipster will add columns here, do not remove-->
</createTable>
To fix this issue add a new changeset with add column as tag ..shown below
<changeSet id="20181209164925-2" author="jhipster" runOnChange="true">
<addColumn tableName="xxxxxx">
<column name="xxxxxx" type="date"></column>
</addColumn>
Refer https://www.liquibase.org/documentation/changes/add_column.html
来源:https://stackoverflow.com/questions/43207163/jhipster-liquibase-validation-error-after-modify-entity