English 中文(简体)
使用 HhibernateTemplate 将数据插入数据库
原标题:Insert data into database using HibernateTemplate

冬眠和春季框架的初学者。 我想使用冬眠模板插入数据库。 我的 DAO 代码 :

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;
    }
}

主计长

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);
}

错误是错误

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

这是DAO代码错误吗?

最佳回答

您的保存方法调用保存方法, 调用保存方法, 调用保存方法, 调用保存方法, 调用保存方法, 调用保存方法, 调用保存方法, 调用保存方法, 调用保存方法, 调用保存方法, 调用保存方法, 调用保存方法...

save(临时 Instance) 替换为 hibertateTemplate.saave(临时Instance)

(请尊重爪哇命名惯例。变量从小写字母开始)。

问题回答

暂无回答




相关问题
Multiple Hibernate instances using C3P0

I am facing a weird problem and it seems to be c3p0 related. I am starting two instances of an app in the same java vm which interact with each other. After some operations "APPARENT DEADLOCK" ...

Hibernate vs Ibatis caching

We can speed up a hibernate app easyly with 2nd level cache using infinispan or ehcache/terracotta,... but ibatis only have a simple interface to implement for caching. And hibernate knows more ...

Using annotations to implement a static join in hibernate

I m relatively new to hibernate and was wondering if someone could help me out. While I have no issues implementing a normal join on multiple columns in hibernate using the @JoinColumns tag, I m ...

Hibernate query with fetch question

I have a 2 entities in a One-To-Many relationship: OfficeView.java: public class OfficeView implements java.io.Serializable { private Integer officeId; private String addr1; private ...

hibernate interceptors : afterTransactionCompletion

I wrote a Hibernate interceptor : public class MyInterceptor extends EmptyInterceptor { private boolean isCanal=false; public boolean onSave(Object entity, Serializable arg1, Object[] arg2, String[]...

How to prevent JPA from rolling back transaction?

Methods invoked: 1. Struts Action 2. Service class method (annotated by @Transactional) 3. Xfire webservice call Everything including struts (DelegatingActionProxy) and transactions is configured ...

Hibernate/GORM: collection was not processed by flush()

I have an integration test in my Grails application that fails when I try to save an entity of type Member invitingMember.save(flush: true) This raises the following exception org.hibernate....

Hibernate Criteria API equivalent for "elements()"

Is it possible to implement the following query using Criteria API? select order from ORDER as order,ITEM as item where item.itemID like ITM_01 and item in elements(order.items)

热门标签