Hibernate - Using Join table - one-to-many association - Lazy Exception
Gilbert johnson
Ranch Hand
Joined: Jul 10, 2005
Posts: 45
posted
0
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.
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.