Hi Friends,
I am new to Hibernate ( 2.5x) and learning it daily.
I am facing issue FETCH.LAZY
I have student-courses one-to-many mapping (collection of courses)
Below is java code :-
function () {
Criteria criteria = getSession().createCriteria(Student.class);
try {
criteria.add(Expression.eq("id", id))
.setFetchMode("courseList",FetchMode.LAZY);
Student student = (Student) criteria.uniqueResult();
return student;
}
}
student model
public class Student
{
private Long id;
private String firstName;
private String lastName;
private Integer age;
private List<Course> courseList;
......
}
<!-- List of course enrolled student mapping -->
<bag name="courseList" table="Student_Courses" lazy="true">
<key column="student_id"/>
<many-to-many column="course_id" class="springapp.domain.Course" />
</bag>
MY PROBLEM : Even I set FECTH mode lazy , I am getting CourseList initialised for that student. If I use Spring's HibernateTemplates get() then courseList collection is NOT initialised. But when I use Criteria API as above or HQL , courseList collection is initialised. I do not want this.
I seach google for half day and found that it is know issue still 3.x . Am I correct ?
Please check -
https://hibernate.onjira.com/browse/HHH-3524Any Help on this really appreciated.
Thanks-