File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Error while trying to get data from Master-Detail tables

 
Juan Carlos
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
Mark Spritzler
ranger
Sheriff
Posts: 17276
6
IntelliJ IDE Mac Spring
  • 0
  • Mark post as helpful
  • send pies
  • 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
Sheriff
Posts: 17276
6
IntelliJ IDE Mac Spring
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, getting all the data before closing the session worked.
 
Juan Carlos
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic