maanantai 20. syyskuuta 2010

c3p0, Spring, Hibernate and NoResultException

I was fighting for a while with NoResultException and c3p0:s config because I thought that was the problem with NoResultExceptions I got. While making uutispuro.fi I finally realized it wasn't the source of the problem.

I had a method doing a persist and a method doing a merge which I had surrounded with try and catch ... and of course with a finally block doing an em.close().

The problem was with the queries doing a .getSingleResult(). I forgot that these might throw the error in hand, and if they did, the closing of entitymanager wasn't done.


try {
Query query = em.createQuery("select query");
return query.getSingleResult();
} catch (NoResultException e) {
log.debug(e);
} catch (Exception e) {
log.error(e);
} finally {
em.close();
}

Ei kommentteja:

Lähetä kommentti

Huomaa: vain tämän blogin jäsen voi lisätä kommentin.