• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How To? Inheritance in Hibernate !

 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ranchers,

Sorry for the posting the topic, twice!

From https://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!
 
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I guess something like this.
 
Prathamesh Gaddam
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic