• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Mapping in Hibernate

 
Guddu Ali
Ranch Hand
Posts: 40
1
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When should we use Inheritance mapping and relational mapping in Hibernate?
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
relational mapping??? No idea what you mean by that as a separate thing. In Hibernate you are mapping to your relational database, so technically all the mapping in Hibernate is relational mapping. And you can't use hibernate without any mapping.

Now Inheritance mapping is different, and it is used for specific reasons. Personally, I actually avoid using Inheritance as much as possible. HOWEVER, there are times where a hierarchical Domain object model is warranted. If you have domain objects that inherit from other domain objects, then you sort of have to use inheritance mapping. Just to make it cleaner. It still isn't required.

Basically, it is about your domain classes. And in Java, I think it is always better to try not to use inheritance in your domain code, but sometimes it is necessary. I still find it rare when I need to use it. My friend on my team though, loves ORM inheritance mapping. ;)

What I find with inheritance mapping is that later when you want to delete data in via ORM code, it becomes a bit tougher to delete it because the data model becomes coupled/intertwined and more difficult to find the right order of deletion of rows through a bunch of db tables.

Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic