This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
The moose likes Other Application Frameworks and the fly likes Hibernate, load GenericHibernateDao Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Reply Bookmark "Hibernate, load GenericHibernateDao" Watch "Hibernate, load GenericHibernateDao" New topic
Author

Hibernate, load GenericHibernateDao

Gerenne Vives
Ranch Hand

Joined: Feb 05, 2005
Posts: 60
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

Joined: Feb 05, 2005
Posts: 60
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.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Hibernate, load GenericHibernateDao
 
Similar Threads
Problem deleting value-type object from Collection in Hibernate
Java Generics Warning
loading from properties file
Configuring SLF4J
failed to lazily initialize a collection - no session or session was closed