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
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

LazyInitializationException

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Hi
I am getting the "org.hibernate.LazyInitializationException: could not initialize proxy - no Session" error while running my application:
I am using the Restful Webservices in GlassFish application server. I configured the Hibernate properties in the persistence.xml file. (GlassFish App server + Hibernate + Restful Webservices(jersey)).
I am using the Lazy loading.

Assume these is the situation:

I have Employee object and Department object.

The department object is declared as the member variable in the Employee object.

Public class Employee {

public int empno;
public String empName;
public Department department;

public void setDepartment(Department dept){
//......
//......
//do something
}

@NotNull
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "XYZ")
public Department getDepartment(){
//......
//......
//do something
}



//setter and getting for each methods
}

public class Department {
//......
//......
}


i am getting this Employee object using EntityManger find method .
I got the employee object and if i exeucte the getEmpNo oir getEmpName , i am getting the value.

but if i try to get the Department(while running the getDepartment method),
I am getting this

"org.hibernate.LazyInitializationException: could not initialize proxy - no Session"

Please could you explaing me , where is the problem and which one causing the problem.
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Please refrain from duplicate posting.

Mark
 
    Bookmark Topic Watch Topic
  • New Topic