I have a unidirectional many-to-many relationship between QuestionGroup and Question where QuestionGroup has a method, "getQuestions()".
I use
Session.load() to load an instance of QuestionGroup and then immediately follow that load with a
Hibernate.initialize(questionGroup.getQuestions()) to load the Questions (which are mapped with
lazy="true"
Code:
QuestionGroupDO qdo = (QuestionGroupDO)session.load(QuestionGroupDO.class, id);
Hibernate.initialize(qdo.getQuestions());
After this I commit the transaction and close the session. What I would expect is that I should now be able to access the Questions in this QuestionGroup without getting a Lazy Initialization Exception. However, this isn't the case. The only value being populated in the Question objects is the QuestionID. When I look at the querys being run, they show the same thing. A full select is run to populate the QuestionGroup and then, when the Questions collection is initialized, a select is being run against the associative table (questiongroup_question) to retrieve the QuestionID but the select doesn't join the question table in order to get the rest of the data needed to populate each Question object in the collection.
What's going on here?
-Matt