jQuery in Action, 2nd edition*
The moose likes Object Relational Mapping and the fly likes Error while trying to get data from Master-Detail tables Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Error while trying to get data from Master-Detail tables" Watch "Error while trying to get data from Master-Detail tables" New topic
Author

Error while trying to get data from Master-Detail tables

Juan Carlos
Greenhorn

Joined: May 20, 2006
Posts: 8
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

Joined: Feb 05, 2001
Posts: 17249
    
    6

"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


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

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

Joined: May 20, 2006
Posts: 8
Thanks, getting all the data before closing the session worked.
Juan Carlos
Greenhorn

Joined: May 20, 2006
Posts: 8
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
 
subject: Error while trying to get data from Master-Detail tables
 
Similar Threads
Retereive data by ORDER BY
Hibernate Issue
problems with Session.save()
could not initialize a collection:
Who can solve that?