• 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
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

Hibernate Design

 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am into trouble.
In my application, I have to show information from multiple tables into a table format. I make a initial query and get some results. The number of rows fetched could be in hundreds and each row fetched contain some id's. now, I have to pick id of each column and from different other table, pull the name of this id. i.e., if I have a row with 7 columns, each column contain a id and the id name has to be fetched from a different table. If i have 7 columns, I have to get the names from 7 tables. This I have to do for all the rows. finally I have to show all the names in a single table.
I saw some where that without writing a query, the data is fetched. like calling the name function on the object for that id. is this possible? or everytime I need to make a query and call the function on the object?
I cannot imagine calling DB multiple times (infact if i have 7 columns and 100 rows fetched, I have to make 700 calls?)
Help me........
Thanks,
Padma.
 
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You want outer join fetching. This is a process whereby the relationships from a row can be recovered as a graph of objects from one single sql query. In hibernate, you can configure outer join fething globally, plus the depth of outer join fetching, with "hibernate.use_outer_join=true" and "hibernate.max_fetch_depth=<whatever>" in hiberenate.properties. It is in fact recommended by the Hibernate people to do this.
(Please note: not all DBs implement outer join fetching - so best check your docs before trying to use it)
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Padma,
Are you using collections in your mappings? If you use one-to-many relationships in a mapping file (I'm assuminng you use one-table-one-mapping-file approach), you'll get a class which has among it's properties, a Set of objects which represents the matching records in the related table. From that object graph you can access all properties of the other table/s,
 
Padma Prasad
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ariel,
Yeah. You are right. I got to know this later.
Thanks for the help.
Padma.
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Padma,

It's not the best design you can provide, but if it's still not good on performance, you can put your query on a Database View and map your hibernate class containing the complete data to this View. The problem is that you put some code on database, creating a high coupling between database and system, but the gains in performance can compensate it.

regards,

Fred
 
Forget Steve. Look at this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic