int类型是不可序列化的,参数传递时,如果传过去后的参数是Serializable,则必须把int型转换为Integer类型如:
public void deleteStation(Integer[] ids) {
try {
stationParDAO.delete(stuIfno.class, ids);
} catch (DAOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
被调用的方法: delete(Class<T> refClass, Serializable[] key)
如果上例中主调方法改为:
public void deleteStation(int[] ids) {
try {
stationParDAO.delete(stuIfno.class, ids);
} catch (DAOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
异常如下:
javax.servlet.ServletException: org.springframework.orm.hibernate3.HibernateSystemException: Provided id of the wrong type. Expected: class java.lang.Integer, got class [I; nested exception is org.hibernate.TypeMismatchException: Provided id of the wrong type.
Expected: class java.lang.Integer, got class [I
org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:515)
org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:419)
org.apache.struts2.dispatcher.ActionContextCleanUp.doFilter(ActionContextCleanUp.java:99)
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:75)
root cause
org.hibernate.TypeMismatchException: Provided id of the wrong type. Expected: class java.lang.Integer, got class [I org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:86) org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:878) org.hibernate.impl.SessionImpl.get(SessionImpl.java:815) org.hibernate.impl.SessionImpl.get(SessionImpl.java:808)