3

I am trying out JHipster (version 6.4.1) using a Monolith and disk-based H2 database. I have created some entities in JDL and have the basic CRUD webpages working. Now that I feel comfortable with the process, I want to add fields and rename others. I figured I could simply update the JDL, re-import the JDL, start the application, and see the result of my changes. What I see is ValidationFailedException from Liquibase and the application throwing HTTP 500 errors due to database problems.

I have looked all over for guidance on the proper process for handling this seemingly common development scenario. Most of the places I have looked for guidance (such as https://www.jhipster.tech/creating-an-entity) discuss importing JDL as a one-time-only operation and do not discuss how to incrementally change and import the JDL.

I have tried a number of suggestions as seen on SO, such as not overwriting the changelogs, doing a liquibase:diff, and adding that to master.xml. This still causes the ValidationFailedException. In the master.xml I see the comment <!-- jhipster-needle-liquibase-add-changelog - JHipster will add liquibase changelogs here --> which leads me to believe that JHipster should be doing the heavy lifting, but I am just missing a step.

I am by no means a JHipster nor a Liquibase expert, but I want to learn. How I can perform simple entity updates without a huge hassle?

[Update with more detail]

After re-importing the updated JDL, I have managed to get rid of the DB Validation Errors by blowing away the database with rm -rf target/h2db/db.

I'm happy with my changes and feel like a commit is in order. What I see is

  • master.xml is unchanged
  • the changelog from the first JDL import has been modified to include the updates I made

If I understand how liquibase works, I would have expected

  1. None of the existing changelogs would be touched
  2. A brand new changelog file would be created that contained just the JDL changes I made this round
  3. master.xml to have changed only in that it would contain an additional changelog entry, pointing to the file created in item 2

Am I misinterpreting how Liquibase represents evolution of the DB schema?

Paul Waldo
  • 1,131
  • 10
  • 26
  • As far as I have been struggling with updates and upgrades, documentation and lessons in the last months regarding JHipster and the liquibase integration, sometimes the only way is to edit the master.xml and other changelog xml-files including the initial one (& adding new ones) on your own like described e.g. in https://www.udemy.com/course/angular-4-java-developers/learn/lecture/8448578. Maybe that's only the case, if there's no "evolution" but (destructive) changes in entities and their relationships. I also thought liquibase would automatically help to not always have to blow away my data. – Jochen Haßfurter Dec 09 '19 at 22:57

1 Answers1

0

It appears that the page you referenced does have some instructions for updating entities. Farther down the page I saw this:

Updating an existing entity

The entity configuration is saved in a specific .json file, in the .jhipster directory. So if you run the sub-generator again, using an existing entity name, you can update or regenerate the entity.

When you run the entity sub-generator for an existing entity, you will be asked a question ‘Do you want to update the entity? This will replace the existing files for this entity, all your custom code will be overwritten’ with following options:

  • Yes, re generate the entity - This will just regenerate your entity. Tip: This can be forced by passing a --regenerate flag when running the sub-generator
  • Yes, add more fields and relationships - This will give you questions to add more fields and relationships
  • Yes, remove fields and relationships - This will give you questions to remove existing fields and relationships from the entity
  • No, exit - This will exit the sub-generator without changing anything

You might want to update your entity for the following reasons:

  • You want to add/remove fields and relationships to an existing entity
  • You want to reset your entity code to its original state
  • You have updated JHipster, and would like to have your entity generated with the new templates
  • You have modified the .json configuration file (the format is quite close to the questions asked by the generator, so it’s not very complicated), so you can have a new version of your entity
  • You have copy/pasted the .json file, and want a new entity that is very close to the copied entity
SteveDonie
  • 8,700
  • 3
  • 43
  • 43