Win a copy of Mastering Corda: Blockchain for Java Developers this week in the Cloud/Virtualization forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

Inheritance Mapping and Relationships

 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am a little confused when it comes to mapping inheritance in JPA (Hibernate Annotations)

I have an entity (AddressLookup) which has a subclass (Landmark). The parent entity is related to another entity (ServiceRequest) OneToMany.

I am using the Table per subclass (JOINED) mapping pattern.

AddressLookup


Landmark


ServiceRequest



Now when writing a query how do I refer to Landmarks via ServiceRequests?

In order for the following to be valid, should I map Landmark to AddressLookup OneToOne?

Landmark landmark = serviceRequest.getAddressLookup.getLandmark();

It is not a problem going the other way since Landmark inherits getServiceRequestCollection from AddressLookup but ServiceRequest knows nothing of the subclass Landmark.

Thanks for any help.

-Brian
 
Ranch Hand
Posts: 380
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
**<Newbie here>

Hello Brian,

ServiceRequest can continue to keep the AddressLookup as the reference point.

Once we get all the AddressLookups linked to ServiceRequest we can keep a method inside AddressLookup which returns the complete

We can keep a method inside the AddressLookup that gets all the Landmarks or any other child classes which may be linked to ServiceRequest. The only issue is the signature of the method :

public AddressLookup getAddressLookup(ServiceRequest sr)
{
//fire query where you retrieve address lookup and the associated extra
information within any child class.
// i.e get landmarks linked through join between AddressLookup and
Landmark (Join being defined through the Id)
// This way if tomorrow some ServiceRequest are linked to Landmark
and others linked to NewlyDefinedLandmarks(Another table extending
AddressLookup) there would be no impact on code.
}

But how can ServiceRequest access the properties specific to Landmark or NewlyDefinedLandmark ?. Casting?.

Regards,
Shivani
 
What do you have to say for yourself? Hmmm? Anything? And you call yourself a tiny ad.
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic