s*****p 发帖数: 5342 | 1 I user HibernateTemplate to use hibernate. However, I met a problem on
session lost or session close.Basically, I did:
Database relationship: 1 student -> n courses
public class Student {
String studentId;
Collection courses;
...
public Collection getCourses(){
return courses;
}
}
public class StudentDAO {
public Student getStudent(String studentId) {
return getHibernateTemplate().get(Student.class, studentId);
}
}
I can get Student object through StudentDAO.
Student student = (S | h**d 发帖数: 474 | 2 are you using lazy loading?
Your hibernate mapping file will help too
【在 s*****p 的大作中提到】 : I user HibernateTemplate to use hibernate. However, I met a problem on : session lost or session close.Basically, I did: : Database relationship: 1 student -> n courses : public class Student { : String studentId; : Collection courses; : ... : public Collection getCourses(){ : return courses; : }
| m******t 发帖数: 2416 | 3 The session is obtained in HibernateTemplate.get(), and released right away
before the method returns. You need to either access getCourses within the
same transaction, or use an OpenSessionInViewFilter/Interceptor - or disable
lazy loading for 'courses' in your mapping (which is usually not a good
idea).
【在 s*****p 的大作中提到】 : I user HibernateTemplate to use hibernate. However, I met a problem on : session lost or session close.Basically, I did: : Database relationship: 1 student -> n courses : public class Student { : String studentId; : Collection courses; : ... : public Collection getCourses(){ : return courses; : }
|
|