• 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

Hibernate, load GenericHibernateDao

 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I have GenericHibernateDao, and I'm working with differents methods, save, listALL, and it's work fine, but in the case of the load method:

@SuppressWarnings("unchecked")
public T load(ID id) {
try{
session=this.getHibernateTemplate();
session.beginTransaction();
T returnValue = (T) session.load(this.domainClass, id);

session.clear();

return returnValue;

}catch (RuntimeException re) {
log.error("find list failed", re);
throw re;
}finally{
if(session != null){
try{
session.close();
} catch(HibernateException e){/*no hacemos nada*/};
}
}
}

Don't throw error, but don't return any object and the id is in the database.

Thanks for all!!
 
Gerenne Vives
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I solved this problem. The line (session.close), must to be deleted:



@SuppressWarnings("unchecked")
public T load(ID id) {
try{
session=this.getHibernateTemplate();
session.beginTransaction();
T returnValue = (T) session.load(this.domainClass, id);

session.clear();

return returnValue;

}catch (RuntimeException re) {
log.error("find list failed", re);
throw re;
}

}

Thanks.
 
Whatever you say buddy! And I believe this tiny ad too:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic