Redian新闻
>
ask a spring framework question
avatar
ask a spring framework question# Java - 爪哇娇娃
s*p
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
avatar
h*d
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;
: }

avatar
m*t
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;
: }

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。