Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

add attributes to user entity in jhipster

I want to add some attributes to the user entity, when I googled about it, I found a similar question :

How to modify existing entity generated with jhipster?

when I followed the steps in this post, I couldn't find the file user.json anywhere as @Roberto montioned

1) Edit the json file representing your entity (add/remove field, the syntax is pretty easy, check in the end of the file if is required any change to the general entity properties like 'fieldsContainOneToMany'...), you'll find it in:

<jhipster_root_folder>/.jhipster/entityName.json

How can I solve this ?

like image 224
Renaud is Not Bill Gates Avatar asked Mar 29 '16 15:03

Renaud is Not Bill Gates


1 Answers

I think the best solution is a compromise between the two solutions offered by @Pedro and @alcuvi (who references to the JHipster Documentation):

  1. First, create an "ExtendedUser" entity with the additional fields (don't forget to use git, you will have to undo this/delete the entity). A one-to-one relationship to "User" is not necessary.

  2. After that, you can copy many parts from "ExtendedUser" to the other parts of the JHipster Application:

    • Liquibase changelog columns (also add them to users.csv)
    • ExtendedUser.java → User.java and UserDTO.java
    • extendedUser-dialog.* → register.html/.controller.js and settings.html/.controller.js
  3. Adapt AccountResource.java and UserService.java (and UnitTests if you use them). This step is mostly done by using getters and setters copied in the step before. JHipster Documentation (https://jhipster.github.io/tips/022_tip_registering_user_with_additional_information.html) might be helpful here.

  4. Delete the "ExtendedUser" Entity (using git, or manually, see also: How to delete an entity after creating it using jhipster?)

The *advantages* are:

  • Using JHipster code generation capabilities
  • No additional entity (which comes with new DB tables and many files)

I hope this information will help other developers in the future!

like image 108
Domi W Avatar answered Oct 05 '22 12:10

Domi W