Generating an entity using a model

We have defined the entities in JDL studio. Now, we will instruct JHipster to generate entities, along with database tables and source code. This process involves the following two tasks:

  • Exporting the entity definitions
  • Importing a JDL file to generate the required artifacts

From JDL-Studio, you can export the definitions as a JDL (.jhfile. JHipster provides a sub-generator that will be used to import the JDL file, with the following command:

jhipster import-jdl <your_jdl_file.jh>

Needless to say, you need to execute this command under the JHipster project directory. Upon successful build and deployment, you will see the School and Teacher entities from the Entities menu. You can also verify that the respective tables are generated. If an application has a large number of entities, it is quite difficult to put all of them in a single JDL file. If there is an error in one entity, the entire process of generating entities will not work properly. In the worst case, if multiple teams are working, then it will create maintenance problems.

JHipster has addressed this issue by allowing multiple JDL files, so that related entities can be grouped into individual JDL files. The import-jdl sub-generator allows importing multiple files separated by spaces. Upon executing this command for the first time, it will generate entities and all of the source code. You need to build and deploy the application with the mvnw command so that the necessary database changes will be reflected.

Second and subsequently, import-jdl will only regenerate the entities that have changed. If you wish to generate all of the entities from scratch again, you will need to add the - force option. Please be aware that this option will erase all customization applied to the entities. Certain validations are caught at the time that we build and deploy the application with the mvnw command, as follows:

  • The maxlength and minlength validations are not allowed on columns of type integer, long, BigDecimal, LocalDate, Boolean, enum, double, and so on.
  • If the service layer is escaped for a given entity, then JHipster shows a warning if the DTO option with mapstruct is selected for that entity. In this situation, the application may not work properly.
  • While adding a single-line comment, you need to put one space after //, or else JHipster will show errors and the entities will not be generated properly.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.27.232