File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes org.hibernate.Exception: could not initialize proxy - the owning Se Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "org.hibernate.Exception: could not initialize proxy - the owning Se" Watch "org.hibernate.Exception: could not initialize proxy - the owning Se" New topic
Author

org.hibernate.Exception: could not initialize proxy - the owning Se

Hemant Pagare
Greenhorn

Joined: Mar 12, 2008
Posts: 9
org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

Yes, you tried to get data that wasn't loaded yet, and you did not have a session open so that Hibernate could get a Connection to the database.

You can only load data into objects when you are within a Session.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Rajan Nath
Greenhorn

Joined: Nov 27, 2007
Posts: 22
you might be using lazy="true" in hbm and then try to use that object. You can change it to false but then performance may take a hit
Hemant Pagare
Greenhorn

Joined: Mar 12, 2008
Posts: 9
my DAO method code is as follows

Query result = createQuery("select timeOfOp,operation,callerFromNumber,callerToNumber from LogsData where timeOfOp >= '"+startDate+"' and timeOfOp <= '"+endDate+"' order by timeOfOp");
List list =result.list();
logger.infoLog("*******Size of List ="+list.size());
Iterator iterator = list.iterator();
LogsData logsData=null;
while(iterator.hasNext()) {
logsData=new LogsData();
logsData = (LogsData)iterator.next();
logsDataList.add(logsData);
}
logger.infoLog("results size="+logsDataList.size());
closeSession();
return logsDataList;
Edvins Reisons
Ranch Hand

Joined: Dec 11, 2006
Posts: 364
As Mark said, you may be trying to do all this outside of a Session.
I see a method for closing the Session, but where was it created?
Hemant Pagare
Greenhorn

Joined: Mar 12, 2008
Posts: 9
Hi Edvin
session was created in superclass which has createQuery method.
Edvins Reisons
Ranch Hand

Joined: Dec 11, 2006
Posts: 364
In a case like this, with the relevant code hidden within a framework´┐Ż Not to exclude that some Rancher would take the challenge and dig into everything, but you'll find a bigger audience if you refactor the code into standard Hibernate usage, as in most books and online examples. And it is not rare to get the problem resolved in the process .
Hope this helps.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: org.hibernate.Exception: could not initialize proxy - the owning Se