my dog learned polymorphism*
The moose likes Object Relational Mapping and the fly likes Extending all my classes from a generic one and configure persistence Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Extending all my classes from a generic one and configure persistence" Watch "Extending all my classes from a generic one and configure persistence" New topic
Author

Extending all my classes from a generic one and configure persistence

danilo fercho
Greenhorn

Joined: Dec 04, 2012
Posts: 4
Hi,

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.

Just that hehe,
Thanks in advanced!
Vinod Tiwari
Ranch Hand

Joined: Feb 06, 2008
Posts: 459
    
    1
1) I think the pattern is Strategy, correct me if I'm wrong.
2) You'll have to create HBM mapping for individual sub class.


Vinod Tiwari | Twitter
 
 
subject: Extending all my classes from a generic one and configure persistence
 
Similar Threads
Common base class for classes extending Action and DispatchAction Classes
Is this a Has-a ?
Add Row with AbstractTableModel
How to have Common base class for classes extending Action and DispatchAction Classe
inheritance