Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem facing with HibernateTemplate

 
Anand Loni
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I am not able to get the dependent objects with HibernateTemplate.



I am able to get the same with hibernate


Below is my mapping file details


Any Idea what went wrong ?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"from Exam

Is this a typo ? ("from Exam ex")

Tell us what error you have. If an exception is raised, please post the full stack trace here.
 
Anand Loni
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes it is typo...

I am not getting any exceptions. When I debug the Exam object, when I select subjects (PersistentSet) I get below error




Is HibernateTemplate capable of getting all depedents ?
 
Anand Loni
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This problem got resolved when I added lazy=false attribute to set
 
Alaa Nassef
Ranch Hand
Posts: 471
Hibernate Mac OS X Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HibernateTemplate opens a session, runs your query, then closes the session for you, hence reducing your code to just one line. Since collections are lazily loaded by default, you will always get an exception if you try to navigate a collection while the session is closed. Making the set load eagerly (like you did) is a solution, but this might have performance problems, since every time you get an exam (or several exams), all of the subjects for this exam (or for each exam in the list you get) will be loaded from the database. Another (better IMHO) solution is to use the open session in view pattern. I have a blog post on that subject (pretty old though). Spring also comes with an OpenSessionInViewFilter, which is pretty useful if your application is a web-app
 
Anand Loni
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply. It worked for me

 
Alaa Nassef
Ranch Hand
Posts: 471
Hibernate Mac OS X Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Glad to help
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic