在做spring和hibernate整合的时候,删除实体时有时经常报java.lang.IllegalArgumentException: attempt to create delete event with null entity这样的错误,今天用junit4做测试删除的时候报了这个错误,感谢网友的帮忙,终于解决。
解决办法是:
将
改成:
解决办法是:
将
@Test
public void deleteUser()
{
UserService us = (UserService) ac.getBean("userService");
User user = us.get(1);
us.delete(user);
}
改成:
@Test
public void deleteUser()
{
UserService us = (UserService) ac.getBean("userService");
User user = null;
if ((user = us.get(1)) != null)
{
us.delete(user);
}
}