• Post Reply 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

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

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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;
 
Ranch Hand
Posts: 364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Every time you till, you lose 30% of your organic matter. But this tiny ad is durable:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic