-1

I need an advice. I'm creating a web app and I should handle multiple type of user. An user is a Customer and another one is an Admin. How can I map this in JPA config? Should I use inheritance?

E.g.

Customer extends User [...]

EDIT

If I take Customer, this "is an" User, as well as, Admin "is an" User. So if I consider "is an" as relationship, Customer table has fields, like address, telephone, etc..., that Admin Table doesn't need. Consequentily, Customer has relationships with other table that they are different about Admin. How could I map this with JPA?

Thanks

Stek
  • 57
  • 1
  • 8
  • No, don’t use inheritance. Use roles. – Nathan Hughes Dec 30 '18 at 16:26
  • @NathanHughes Yeah, I've forgotten a particular. I'm already using roles. I would split the logic of every User Entity. Because I don't need to save all fields of a customer for an admin. – Stek Dec 30 '18 at 16:33
  • It sounds like the code for that should be in different services. See [my answer about what should be in a controller vs what should be in a service](https://stackoverflow.com/a/3885783/217324). – Nathan Hughes Dec 30 '18 at 17:59
  • In my opinion, It isn't an issue about controller and service. My "sub-users" have several relationship with other tables, so I would keep this "logic" on Entities side. – Stek Dec 30 '18 at 18:19
  • 2
    Maybe you could add few concrete example entities and logic - minimal - to clarify your question a bit. – pirho Dec 30 '18 at 18:52
  • Maybe the word "logic" has confused. If I take Customer, this "is an" User, as well as, Admin "is an" User. So if consider "is an" as relationship. Customer table has fields, like address, telephone, etc..., that Admin Table doesn't need. Consequentily, Customer has relationships with other table that they are different about Admin. How could I map this with JPA? – Stek Dec 31 '18 at 01:00

1 Answers1

1

Finally, I followed this guide: https://vladmihalcea.com/the-best-way-to-use-entity-inheritance-with-jpa-and-hibernate/

So, I used strategy = InheritanceType.JOINED for my purpose.

Stek
  • 57
  • 1
  • 8