Search code examples
jhipster

Trying to create a user account from a new entity


First of all i'm new to Jhipster, i've read the official documentations but i still can't seem to find a solution to my problem (i've been stuck for almost 3 weeks now), that's why i decided to ask here for help.

So, i have an application where i need to create an entity called employee and i need to create a user account with the additional fields taht are specified in the employee entity, so in other words, when i fill the form to create a new employee that will not only create a new one but it will also automatically create a user account for that emplyee.

What i've tried doing up until now, is creating a new employee entity and link it with a OneToOne relashionship to the USER entity (created by Jhipster) but the thing is, in that case i would have to create a new user and then add the additional information for the employee, wheareas i need it to be in the same form, to create an employee and the user linked to it at the same time.

Any help will be really appreciated.


Solution

  • What you want to do is not supported off the shelf by JHipster, you have to code it manually.

    In backend, you could do it by defining a DTO that combines both entities, a RestController that exposes it and a service that is responsible for orchestrating persistence.

    In frontend, it's the same you have a component that contains the form to update this DTO and call your REST API.

    Alternatively, if a User is always an Employee, you could also merge them in a single User entity.

    Of course, this depends on which authentication type you selected which defines where users are managed.