The easiest way is probably the HibernateCallback, that way you can leave most of the code as is. You only need to wrap it in a callback (as my example) and remove the getSession call (replace it with session).
The easiest way is probably the HibernateCallback, that way you can leave most of the code as is. You only need to wrap it in a callback (as my example) and remove the getSession call (replace it with session).
Marten Deinum
Java Consultant / Pragmatist / Open Source Enthousiast / Author
Pro Spring MVC: With Web Flow
Conspect
Have you read the reference guide.
Use the [ code ] tags, young padawan
I have determined that the piece of code that is accessed about 75% over everything else, is our "view article" function (think news service). It looks like:
Do you see any possible db leaks there?Code:public Object getByField(String fieldName, String fieldValue) throws DaoServiceException { try { String query = "from myco.dom.Article as a where " + fieldName + " = '" + fieldValue + "'"; query += " order by " + this.orderByColumn; List objs = getHibernateTemplate().find(query); if(objs != null && objs.size() > 0) { Article art = (Article)objs.get(0); return getHibernateTemplate().load(Article.class, new Integer(art.getId())); } else { return null; } } catch(Exception e) { throw new DaoServiceException(e); } }
Thanks
A lot of things could be said about that piece of code, but there is no connection leak in it.![]()
This is why I pay our developers so much money....
(Ok, so I won't admin it's mine!)