包装类和基本数据类型引起的bug
if (null != entity.getId() && appApplicationDao.get(entity.getId()).getOwner().getId() != entity.getOwnerId()) {...}
采用SSH框架,hibernate进行数据封装,返回实体对象, 所以getXXX()方法返回都是对象。
id返回为Long类型,包装类最好不要直接进行比较,因为不知道其是Long id = 1000
,还是Long id = new Long(1000)
,所以最好加上longValue()转换为long基本数据类型再进行比较。
if (null != entity.getId() && appApplicationDao.get(entity.getId()).getOwner().getId().longValue() != entity.getOwnerId().longValue()) {...}