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.
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)
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,
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.
Always! Wait. Never. Shut up. Look at this tiny ad.