i'm mapping some classes in hibernate, these classes are basically a strategy pattern. I have a class "User" that knows an abstract class "UserType" that declares an abstract method "purchaseSomething()", the subclasses override this method. For now, i'm mapping all the classes as entities, thus i have three tables. Each time that an user submits to the system, when I persist the user, this saves his UserType subclass instance in the tables. That i want it's have a single table called "UserTypes" wich have only two colums "id" and "type", thus every "Admin" user will point to the same row in the table, every "Customer" user will point to the same row in the table, instead that I already have where an "Admin" user points to the row with id 23435 on the table "AdminUser", and another "Admin" user points to the row with id 54234 on the table "AdminUser".
Thanks, any tip will be usefull.
For a pure Strategy pattern, consider making your type an Enum and using the JPA Enumeration
annotation. You can still give the Enum abstract methods to fill in your strategies.
However, it sounds like you actually might want to store data separately about Administrators and Customers. If a user is a Customer or Administrator but not both, create subclasses and use joined-subclass. If a user could be both, perhaps you just want a one-to-one relationship mapping.