This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Hello, First of all - want to thank everyone who contributes in this forum. It has helped me immensely so many times when I have been stuck.
Right now I am on my quest to learn hibernate and have already asked questions here before.
I have two tables - Group and Product which have a bi-directional many-to-many relationship. A group can have many products and a product can belong to many groups.
So I introduced a join table "Group_Product" - now this table has an extra column userID. So one of the members of this forum suggested two approaches - and I went with the approach of using two one-to-many associations. Everything is working fine.
Now I want to retrieve all products that belong to a particular Group. In my Java Code - using groupId, I'm loading the Group object. From my Group object - I'm getting a set of GroupProduct. Now GroupProduct has objects Group and Product and userId as members.
Now in my java code, I have:
The code is printing userID and productID but throws an exception while printing productName.
I know thats because, its only querying Group and Group_Product table. Its not linking Group_Product table with Product table.
What am I missing. Really appreciate your responses. Thanks
Here are my hbm.xml files Group.hbm.xml
[ March 26, 2008: Message edited by: Gilbert johnson ]
LazyInitializationExceptions occur when Hibernate tries to get data from the database, but there is no longer a Session open. Basically, where you are trying to access the other data Hibernate wants to run a query against the database, but it can't get a Connection to the database, which it gets from the Session object, which is no longer open or available.