控制台打印:
- relayStationIds--------------322,321,320,319,
- ids[0]--------------322
- id[0]-------------322
- 2011-5-10 17:00:46 org.apache.struts.chain.commands.AbstractExceptionHandler execute
- 警告: Unhandled exception
- org.springframework.orm.hibernate3.HibernateSystemException: Unknown entity: java.lang.Long; nested exception is org.hibernate.MappingException: Unknown entity: java.lang.Long
- ...
- ...
- Caused by: org.hibernate.MappingException: Unknown entity: java.lang.Long
- ...
- ...
- ... 65 more
- 2011-5-10 17:00:46 org.apache.struts.chain.commands.ExceptionCatcher postprocess
- 警告: Exception from exceptionCommand 'servlet-exception'
- org.springframework.orm.hibernate3.HibernateSystemException: Unknown entity: java.lang.Long; nested exception is org.hibernate.MappingException: Unknown entity: java.lang.Long
- ...
- ...
- Caused by: org.hibernate.MappingException: Unknown entity: java.lang.Long
- ...
- ...
- ... 65 more
报异常的代码:
- public void deleteRelayStationById(long id) throws GISException {
- this.getHibernateTemplate().delete(new Long(id));
- }
解决方法:传入实体对象
- public void deleteRelayStationById(long id) throws GISException {
- RelayStation rs = new RelayStation();
- rs.setRelayStationId(new Long(id));
- this.getHibernateTemplate().delete(rs);
- }
明显可以看出,HibernateTemplate是通过删除对象的方式来删除的,简单的传入一个属性,就会报以上异常。
因此需要将属性set到实体对象中,然后通过在delete()方法中传入实体对象即可实现删除。