读取时出现StackOverflowError然后用hibernate删除对象

时间:2011-02-23 22:24:25

标签: hibernate spring stack-overflow

我正在读取一个对象然后简单地删除它并抛出java.lang.StackOverflowError!

public class TestDummy extends TestCase {

    @Autowired
    private ApplicationContext context;

    @Autowired
    private AccountDao accountDao;



public void testDeleteAccount(){

        Account acc = accountDao.get("9BE4BFA718EA4B4EE044000077B05A84");
        System.out.println("Account name is "+acc.getAccountName());
        accountDao.delete(a);

    }

}

accountDao和context正在实例化。

这里是get()和delete()方法

   public Account get(String id) {
    Account acc = getHibernateTemplate().get(Account.class, id);
    return  acc;
}

public void delete(Account account) {
    delete(account);
}

我想知道这里可以递归发生什么!

请建议。

2 个答案:

答案 0 :(得分:2)

public void delete(Account account) 
{
   delete(account);
}

难怪你得到了。

答案 1 :(得分:1)

导致堆栈溢出的递归在这里被无耻地隐藏:

public void delete(Account account) {
    delete(account);
}