Once you have created your application, you will want to create entities. For example, you might want to create an Author and a Book entity. For each entity, you will need:
If you have several entities, you will likely want to have relationships between them. For this, you will need:
The "entity" sub-generator will create all the necessary files, and provide a CRUD front-end for each entity.
If you created your application with MongoDB instead of a more classical SQL/JPA solution, JHipster will still generate your entities correctly (you will have MongoDB documents instead of JPA entities), but of course you won't be able to have relationships between your entities.
This is a short tutorial on creating two entities (a Author and a Book) which have a one-to-many relationship.
As we want to have a one-to-many relationship between Authors and Books (one author can write many books), we need to create the Author first. At the database level, JHipster will then be able to add a foreign key on the Book table, linking to the Author table.
yo jhipster:entity author
Answer the next questions concerning the fields of this entity, the author has:
Then answer the questions concerning the relationships, the author has:
yo jhipster:entity book
Answer the next questions concerning the fields of this entity, the book has:
Then answer the questions concerning the relationships, the book:
Run the generated test suite, with mvn test
, which will test the Author entity and the Book entity.
Launch the application (for example with mvn spring-boot:run
), log in and select the "Author" and "Book"
entities in the "entities" menu.
Check the database tables, to see if your data is correctly inserted.
The generated files contain all the basic CRUD operations, and don't need to be modified if your needs are simple.
If you want to modify the generated code or the database schema, you should follow our development guide
If you want some more complex business behaviors, you might need to add a Spring @Service
class, using the service sub-generator.
Your generated CRUD page should look like this: