• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

Problem facing with HibernateTemplate

 
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ?
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This problem got resolved when I added lazy=false attribute to set
 
Ranch Hand
Posts: 471
Mac OS X Hibernate Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply. It worked for me

 
Alaa Nassef
Ranch Hand
Posts: 471
Mac OS X Hibernate Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Glad to help
 
reply
    Bookmark Topic Watch Topic
  • New Topic