aspose file tools*
The moose likes Spring and the fly likes Problem facing with HibernateTemplate Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Problem facing with HibernateTemplate " Watch "Problem facing with HibernateTemplate " New topic
Author

Problem facing with HibernateTemplate

Anand Loni
Ranch Hand

Joined: Jan 20, 2006
Posts: 150
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 ?


~ Anand,
SCJP 1.5, SCWCD 1.5
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

"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.


[My Blog]
All roads lead to JavaRanch
Anand Loni
Ranch Hand

Joined: Jan 20, 2006
Posts: 150
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

Joined: Jan 20, 2006
Posts: 150
This problem got resolved when I added lazy=false attribute to set
Alaa Nassef
Ranch Hand

Joined: Jan 28, 2008
Posts: 467
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


Visit my blog: http://jnassef.blogspot.com/
Anand Loni
Ranch Hand

Joined: Jan 20, 2006
Posts: 150
Thanks for the reply. It worked for me

Alaa Nassef
Ranch Hand

Joined: Jan 28, 2008
Posts: 467
Glad to help
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem facing with HibernateTemplate