• Post Reply Bookmark Topic Watch Topic
  • New Topic

Extending Hibernate mapped class?

 
Fedor Smirnoff
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • 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.!
 
Gravity is a harsh mistress. But this tiny ad is pretty easy to deal with:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!