HI All
I have a problem that I just cant seem to solve. In my DAO that extends HibernateDaoSupport I execute the following code:
List students = getHibernateTemplate( ).find( "from Student s where s.userId=? and s.password=?", new Object[ ] { userId, password } );
Student is a class with a user and password property that has been mapped to 2 fields. It also contains a reference to a teacher object. It is mapped to the teacher as a many-to-one association.
The teacher object has a set of students that is also mapped.
I use a valid login to verify a student and indead the student is loaded using hibernate. The problem is that the teacher property in the Student class isnt initialized. This is correct. I want to control where the teacher property is loaded.
In my DAO I have this code:
Student student = students.get(0);
student.getTeacher();
student.getTeacher().getName(); // Name is a property of teacher
I have tried litterly everything. I have put lazy="true", lazy="false" everywhere in the mappings of Student and Teacher. I have even called getHibernateTemplate().initialize(student.getTeach er()). Nothing and I mean nothing seams to initizlize the teacher object. I dont get any errors or nothing. When I debug using eclipse it indicates that all the fields in the Teacher object are null.
To make it clear I only want to initialize the teacher object when I call student.getTeacher() in my DAO
Can anybody help?


Reply With Quote
