This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Hemant Pagare
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Rajan Nath
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 364
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Edvin
session was created in superclass which has createQuery method.
 
Edvins Reisons
Ranch Hand
Posts: 364
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic