• Post Reply Bookmark Topic Watch Topic
  • New Topic

Extending Hibernate mapped class?  RSS feed

Fedor Smirnoff
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.!
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!