jhipster / generator-jhipster

JHipster is a development platform to quickly generate, develop, & deploy modern web applications & microservice architectures.
https://www.jhipster.tech
Apache License 2.0
21.56k stars 4.02k forks source link

modify existing User entity field #1623

Closed liuxx532 closed 9 years ago

liuxx532 commented 9 years ago

Hello, I just start to work on Jhipster, and got a question "Can I modify the exiting User entity field (normally expand the field) ?"
Like, sometimes I want to collect more information from users when users register. I tried to "yo jhipster:entity user" to expand the filed, however, I am failed. I record the original field and typed them in when I "yo jhipster:entity user", but there are many methods related to the original field and I am unable to handle them very well.

So, I hope you have a good way to expand the user field, and share with me. Thank you very much.

liuxx532 commented 9 years ago

Hope I have demonstrated clearly, Thank you.

atomfrede commented 9 years ago

You could create a new entity with your additional data and just a relation between user and your new entity.

gmarziou commented 9 years ago

Maybe the default entities like User could have a JSON description in .jhipster directory as custom ones have and so could be extended using entity sub generator?

atomfrede commented 9 years ago

:+1: @gmarziou Sounds great (what when the developer removes required fields?)

gmarziou commented 9 years ago

Well if you use a knife, you can hurt yourself and git is your best friend ;)

atomfrede commented 9 years ago

Yes of course, but you never know what people try to do ;)

liuxx532 commented 9 years ago

@atomfrede your idea could be work. But how can I build the relation between the new entity and user? If With a foreign key I also need to expand the filed. The previous question comes back again

deepu105 commented 9 years ago

@liuxx532 as of now you have to manually edit the entity and changelog files by hand to achieve this. You can create a userProfile entity and have it as a one to one in user entity but u have to manually add that in the user entity and edit changelog to add the foreignkey of userProfile to usertable

liuxx532 commented 9 years ago

@deepu105 I think Your suggestion is quit similar as @atomfrede, and actually I was trying to approach that. Firstly I tried to re-generate the user with a additional foreign key, but u know User is related with Anthority and PersistentToken, I tried my best to rebuild the relationships among them three, however there are always some errors(too much import and dependencies make the rebuild get very hard.)

liuxx532 commented 9 years ago

I think many people sometimes want to re-generate the User entity to meet different kinds of requirements. Then I am to state my way to approach that, definitely it is not totally correct(Lol) but I hope we can discuss. Firstly, yo jhipster:entity user. Fill the fileds in, set authorities as Integer, set persistentTokens as Integer as well, build one2many relationship with Authority and PersistentToken respectively. Build many2one relationship with PersistentToken by "Id" Secondly, yo jhipster:entity Authority, fill fileds in, build many2one relationship with user by "id".

Thirdly, yo jhipster:entity PersistentToken. Fill fields in, set "user" as integer, build many2one relationship with user by "id", and build one2many relationship with user by "user".

Hopefully, you can understand the way that I described above. More than welcome to point out the Errors or Bad choice. (@deepu105, @atomfrede,@gmarziou)

liuxx532 commented 9 years ago

@jdubois Hope you can come to here, and give me some suggestion. Please have a look the process to rebuild the User entity is correct or not. Thank you very much.

phouverneyuff commented 9 years ago

@liuxx532 , extend the table JHI_USER. I made tree types of user using generalization.

http://infocenter.sybase.com/archive/index.jsp?topic=/com.sybase.stf.powerdesigner.docs_12.0.0/html/clug/clugp114.htm

image

liuxx532 commented 9 years ago

@phouverneyuff Thanks a lot for your ERD, but it looks like I am unable to see the full diagram(cannot see the right part), and I cannot access the url: """ http://infocenter.sybase.com/archive/index.jsp?topic=/com.sybase.stf.powerdesigner.docs_12.0.0/html/clug/clugp114.htm """.

Thank you.

phouverneyuff commented 9 years ago

@liuxx532 , I cut my ERD to you see only this part.

I made generalization. Gestor(manager), Cliente(client) and Funcionario(employee) are kind of User. The relationship between them are one-to-one(1:1).

Type in Google Images "Generalization" and you will see other examples.

https://www.google.com.br/search?q=generalization&safe=off&espv=2&biw=2133&bih=1100&source=lnms&tbm=isch&sa=X&ei=f8OIVbeKJ8n5-AGZwbG4AQ&ved=0CAYQ_AUoAQ&dpr=0.9#safe=off&tbm=isch&q=generalization+user

MathieuAA commented 9 years ago

@atomfrede As a JHipster-UML guy, I couldn't agree more. Composition is the best solution (and it should be preferred over inheritance in this case). The only advantage inheritance has (here) is that we don't have to modify the User entity. However, inheritance still needs to be correctly implemented (which, to my knowledge, is not). On the other hand, composition requires the User entity to be altered... if we don't use unidirectional associations. We (the JHipster-UML team) encountered this case before, and dealt with it by removing associations going from User (but we kept the ones going to User), and converting bidirectional associations to unidirectional ones.

jdubois commented 9 years ago

-> so I would use my first solution, which is really basic in fact

fsopjani commented 8 years ago

ERROR! The table name cannot contain a PostgreSQL reserved keyword

guilhermefalcao commented 8 years ago

I have the same error when trying to add a new relationship (1-1) User(newEntity_id) - NewEntity(id).

Any solution?

gmarziou commented 8 years ago

Please don't camp on old issues, open a new one and follow our guidelines