当前位置: 代码迷 >> Web前端 >> 关于attempt to create delete event with null entity的错误
  详细解决方案

关于attempt to create delete event with null entity的错误

热度:1102   发布时间:2012-10-23 12:12:22.0
关于attempt to create delete event with null entity的异常
在做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);
		}

	}

  相关解决方案