aspose file tools*
The moose likes Object Relational Mapping and the fly likes ORM - POJO Composition Vs Inheritance Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "ORM - POJO Composition Vs Inheritance " Watch "ORM - POJO Composition Vs Inheritance " New topic
Author

ORM - POJO Composition Vs Inheritance

Abhishek khare
Greenhorn

Joined: Aug 08, 2007
Posts: 25
I am currently writing a complete new application, I am planning to use Hibernate for ORM.

The Question is when designing the POJO for the App, should we prefer Composition or Inheritance.

It will be helpful, if some one can explain the Advantage and Disadvantage of both and scenario when either should be used.

Thanks In Advance.


"Things come to those who wait, but only the things left by those who hustle."
Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1672
    
    7

I would drop the ORM and hibernate out of this question and ask it in the OO, Patterns, UML and Refactoring forum. One of the purposes of an ORM framework is to be able to write your application in terms of the domain without having to worry about tables, columns, and keys. That said your question should really be:

For <insert your specific use case here> is composition or inheritance more appropriate?

That said the general consensus is to prefer composition to inheritance, but that is not to say inheritance does not have a place. Also this is not the forum for that discussion.

From an ORM perspective composition is less complicated but once again that is not to say inheritance does not have its place. I know that this was kind of a sideways answer to your question but I would not let a framework determine whether you use composition or inheritance. That should be determined by your use case and your domain.


[How To Ask Questions][Read before you PM me]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: ORM - POJO Composition Vs Inheritance