Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Extending all my classes from a generic one and configure persistence

 
danilo fercho
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 466
1
IntelliJ IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic