Extending all my classes from a generic one and configure persistence
posted 3 years ago
I'm starting a litle project, so I'll need to persist my objects model and also marshall and unmarshall them in order to use them in REST services.
In some place that I don't remember, I saw that all the classes were extending from a generic class, this class just defines the ID, so any object have by default the ID.
Let's say I have classes Person, Process and Money, three classes that have nothing in common for my model and a 4th one called Element, this defines the ID and nothing else. And all the other classes extends this class.
I want to ask 2 thinks
1.Is this a pattern design?, and if so, the name of it and the beneficts of using this, and when should I use it. I'm lost.
Currently the advantages I see is that you only define the ID one time, not in all classes and that could represent less code in your classes or hbm.xml files .
2. If I decide to use that model, how to configure hibernate in order to do not put all the objects in just one table (Element in the example), so I can have tables Person, Process and Money. Currently I'm getting just Element table (Element), with ALL the attributes of all the objects, leaving as null the not related attributes.