Error while trying to get data from Master-Detail tables
Juan Carlos
Greenhorn
Joined: May 20, 2006
Posts: 8
posted
0
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
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.
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
Joined: May 20, 2006
Posts: 8
posted
0
Thanks, getting all the data before closing the session worked.
Juan Carlos
Greenhorn
Joined: May 20, 2006
Posts: 8
posted
0
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