I’m beginner at hibernate and spring framework. I want to insert into database using hibernate template. My DAO code:
public void save(News transientInstance) {
log.debug("saving News instance");
try {
save(transientInstance);
log.debug("save successful");
} catch (RuntimeException re) {
log.error("save failed", re);
throw re;
}
}
Controller
public void insert(NewsForm newsForm, RequestContext context) {
NewsDAO NewsDAO = (NewsDAO) ApplicationContext.getApplicationContext().getBean("NewsDAO");
News newNews = new News();
Timestamp date = new Timestamp(System.currentTimeMillis());
newNews.setDate(date);
newNews.setTitle(newsForm.getTitle());
newNews.setDescription(newsForm.getDescription());
newNews.setBody(newsForm.getBody());
newNews.setStatus(newsForm.getStatus());
newNews.setUpdateDate(date);
NewsDAO.save(newNews);
}
Error is
Caused by: java.lang.StackOverflowError
at org.apache.commons.logging.impl.Log4JLogger.debug(Log4JLogger.java:177)
dao.NewsDAO.save(NewsDAO.java:68)
dao.NewsDAO.save(NewsDAO.java:68)
dao.NewsDAO.save(NewsDAO.java:68)
dao.NewsDAO.save(NewsDAO.java:68)
dao.NewsDAO.save(NewsDAO.java:68)
dao.NewsDAO.save(NewsDAO.java:68)
dao.NewsDAO.save(NewsDAO.java:68)
dao.NewsDAO.save(NewsDAO.java:68)
dao.NewsDAO.save(NewsDAO.java:68)
dao.NewsDAO.save(NewsDAO.java:68)
dao.NewsDAO.save(NewsDAO.java:68)
dao.NewsDAO.save(NewsDAO.java:68)
dao.NewsDAO.save(NewsDAO.java:68) ...etc
Is this DAO code wrong?
Your save method calls the save method, which calls the save method, which calls the save method, which calls the save method, which calls the save method, which calls the save method, which calls the save method, which calls the save method, which calls the save method…
Replace
save(transientInstance)byhibernateTemplate.save(transientInstance).(and please respect the Java naming conventions. Variables start with a lower-case letter).