-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: urgent
PostPosted: Thu Apr 01, 2010 6:16 pm 
Newbie

Joined: Thu Apr 01, 2010 6:09 pm
Posts: 8
Hi

I work with a hibernate spring application. I have a student domain object and school object. In student, I have the following mapping
Code:
@ManyToOne(fetch = FetchType.LAZY)
   @JoinColumn(name = "school_identifier", referencedColumnName = "identifier", nullable = false)
   public School getSchool() {
      return this.school;
   }


In this case, the column 'identifier' is not the primary key of table School.

Here I am able to use student.getSchool() outside the session in a view template.

However, if the column 'identifier' becomes the primary key of the table School

the code student.getSchool() outside the session in a view template causes LayInitialization Exception

Can any one please help me in understanding this. It is driving me crazy!

I would be vv thankful if someone explains whats happening here

Thanks
Priya


Top
 Profile  
 
 Post subject: Re: urgent
PostPosted: Fri Apr 02, 2010 2:04 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
As you define @ManyToOne(fetch = FetchType.LAZY) the School instance is not read from database together with your Student instance. Hibernate tries to read the school as latest as possible, which is the moment where you explicitly call
student.getSchool().
But In this moment, as you state, you are not in session anymore.
But hibernate needs a session in order to can read the school-instance from the persistence,
therefore a LazyInitialization Exception is thrown.
Hope this explanation was clear.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.