0

For my application is have two kinds of users. A Customer and a Retailer. I would like to store them both in the same 'users' table for authentication reasons. But both the Customer and Retailer have same and different values.

They both have a name, password, id... But they also both have different values, the Customer has an address. And the Retailer has a list of products.

I would like to use composition. Like this: Example of composition

So both the Retailer and Customer have the UserDetails. But they also have their own separate values like address or products.

Would this be a smart way of doing it. Or am i better of having both users in a seperate table?

Also because i'm using Hibernate i need to be able to map my classes to my database. What would be the best way of going about this?

dirk.z
  • 93
  • 1
  • 3
  • 9

1 Answers1

0

Technically, in terms of good practice I think you took right approach. If happens you will need add any additional field, then no problem should occur. What makes it flexible.

As I guess, the user who's registering will be provided a role, either retailer or customer.

First thought that came to my mind was maybe using inheritance relation. But in this case if you will be using any type of security, single table for all users credentials will be alright. You won't have to struggle with authorization/authentication so much.

Kamil K
  • 32
  • 4
  • Of course I'm looking at it from Spring Security perspective, because in case of implementing UserDetails interface you still will be able to use single table without figuring out and implementing some kind of conditions for specific user type. – Kamil K Nov 27 '20 at 21:24
  • 1
    Thanks for explaining that i got the right idea. Would you be able to point me in the right direction with some helpful tutorials? i would really appreciate it – dirk.z Nov 27 '20 at 21:25
  • From what I know, you will have Spring on server side? – Kamil K Nov 27 '20 at 21:28
  • I use Jersey and H2 for server side. But i think it's pretty much the same with hibernate mapping – dirk.z Nov 27 '20 at 21:30
  • http://persistentdesigns.com/wp/jersey-spring-and-jpa/ – Kamil K Nov 27 '20 at 21:33
  • And this one points to stackoverflow, rest implementation https://stackoverflow.com/questions/11190934/rest-with-java-jax-rs-using-jersey – Kamil K Nov 27 '20 at 21:33
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/225239/discussion-between-dirk-z-and-kamil-k). – dirk.z Nov 28 '20 at 10:39