Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How To? Inheritance in Hibernate !

 
Prathamesh Gaddam
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ranchers,

Sorry for the posting the topic, twice!

From http://www.coderanch.com/t/439786/Object-Relational-Mapping/java/polymormsim-related-demos

2.1. Table per class hierarchy .....


I need to check the how schema will be generated for subclasses extending the sublass (using "hibernate.hbm2ddl.auto"). In simple, I want to extend AudioDisc class as:


In Disc.hbm.xml
How to code the mapping file?
Can we use multiple discriminator in a <class></class>? Or a discriminator in the <subclass></subclass>?
Can we have <subclass/> within <subclass></subclass>? How can i use this features?
Or can I use, already defined <subclass/> as a <class>? For example w.r.t above example can we use as <class name="AudioDisc">as:



Thank you in advance!
 
Reehan Lalkhanwar
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess something like this.
 
Prathamesh Gaddam
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you, Reehan !

I guess there might be a mis-understanding. No Problem !!

I have already subclassed/extended(AudioDisc.java & VideoDisc.java) from the super-class(Disc.java).

Now I need to further extend from the sub-class (AudioDisc.java), and code the mapping file. How to map these extended sub-classes? And using three basic inheritance/polymorphism strategies.



Please feel free to post reply, for any elaboration.

Warm regards!
 
Reehan Lalkhanwar
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lemme put some code similar to what I use currently.
Its sublcass:
Further subclass:
and on and on...
Hope that helps.
 
Prathamesh Gaddam
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes! I was expecting something like this.

1. The sample code worked ! Thank you, Reehan! However, the existing data from the table (dbo.Disc) was deleted. Why? I used <property name="hibernate.hbm2ddl.auto">update</property> for schema generation.

2. I guess, the inheritance strategy used in the given example is Table-per-ClassHierarchy(<subclass>). So there should be a new table for each new hierarchy of subclasses extended from parent-class/sub-class. Please correct; if wrong and quote towards it with any relavent example!

Thank you once again for your patience, Reehan!

Warm regards
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic