• 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
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Extending Hibernate mapped class?

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

I am working with an existing application and trying to find a best way to implement new changes. In this particular situation I have a class that I cannot change, similar to (to keep things simple):

public Class Category {
private String name;
private Category parentCategory;
private Set childCategories = new HashSet();
......
}

This class is mapped to a single table that stores parents and children. Now I am adding a new table to the database, lets call it category_property and mapping a class to it CategoryProperty, one-to-one to Category.

Now I need to query all categories with its properties from the database and display it on one page kind of like:

category 1 - property
--child of category 1 - property
--child of category 1 - property
category 2 - property
......

I obviously want to limit amount of calls to the database. What are my options?:

1. I cannot modify Category class to include the relationship to CategoryProperty and force eager fetch.

2. Doing a joint call and return array of pairs of Category and CategoryPorperties would require me to sort parents and children for display. Is this the way to go?

3. ??? Would the best option be declaring another mapping, like CategoryWithProperty extends Category and declaring all mappings again in CategoryWithProperty.hbm.xml and one-to-one relationship?

I am sure you have more ideas Thanks.!
 
Bras cause cancer. And tiny ads:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic