• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Error while trying to get data from Master-Detail tables

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am pretty new to Hibernate and needs some help in resolving the following issue. I am trying to retrieve Menu and SubMenus data from
Database tables. I have two tables Menu and SubMenu. I can save the data fine. But when trying to get the data I get errors. How can I query on the Menu table to give me all the data in that table along with
data in the SubMenus table. Following are the hbm.xml files.



Code that handles the save part



Here I am trying to get the saved data, but it throws an error when trying to get the SubMenus for a Menu




Here is the error I am getting



How to get all the data from Master and detail table while querying on Master table. Any help is appreciated. Thanks
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"White Sox"

Please click on the My Profile Link above and change your display name to meet the JavaRanch Naming Policy of using your real first and real last names.

Thanks

Mark
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, so here



you close the Session, then after that try to get the child data. But the CHild data is lazy loaded, meaning when you first get the Parent object, the children Collection in it is not loaded, it is empty. It is when you get the Collection and start going through it that Hibernate will get the data, but you closed the session, so Hibernate can't get the data.

So either 1. Set lazy loading to false, or 2. don't close the session till after you have read everything.

And remember to change your display name.


Mark
 
Juan Carlos
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, getting all the data before closing the session worked.
 
Juan Carlos
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have one more issue and any help is appreciated. How can I keep the order of my detail records i.e. Sub Menus keep changing there order as I want them to show in same order. Right now everytime I refresh the page Sub Menus order keeps changing. Any help is appreciated. Thanks
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic