nested exception is java.lang.ClassCastException:XXX cannot be cast to java.io.Serializable

Type Exception Report

Message Request processing failed; nested exception is java.lang.ClassCastException: cn.com.ecict.bean.UserBean cannot be cast to java.io.Serializable

Description The server encountered an unexpected condition that prevented it from fulfilling the request.

Exception

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.ClassCastException: cn.com.ecict.bean.UserBean cannot be cast to java.io.Serializable
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:982)
    org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:661)
    org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197)
    org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)

Root Cause

java.lang.ClassCastException: cn.com.ecict.bean.UserBean cannot be cast to java.io.Serializable
    org.hibernate.type.ManyToOneType.hydrate(ManyToOneType.java:179)
    org.hibernate.persister.entity.AbstractEntityPersister.hydrate(AbstractEntityPersister.java:2844)
    org.hibernate.loader.Loader.loadFromResultSet(Loader.java:1741)
    org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1667)
    org.hibernate.loader.Loader.getRow(Loader.java:1556)
    org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:740)
    org.hibernate.loader.Loader.processResultSet(Loader.java:985)
    org.hibernate.loader.Loader.doQuery(Loader.java:943)
    org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:349)
    org.hibernate.loader.Loader.doList(Loader.java:2615)
    org.hibernate.loader.Loader.doList(Loader.java:2598)
    org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2430)
    org.hibernate.loader.Loader.list(Loader.java:2425)
    org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:502)
    org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:379)
    org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:216)
    org.hibernate.internal.SessionImpl.list(SessionImpl.java:1488)
    org.hibernate.query.internal.AbstractProducedQuery.doList(AbstractProducedQuery.java:1445)
    org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1414)
    cn.com.ecict.dao.impl.BaseDaoImpl.find(BaseDaoImpl.java:63)
    cn.com.ecict.dao.impl.ContainerDaoImpl.getContainerList(ContainerDaoImpl.java:24)
    cn.com.ecict.service.impl.ContainerServiceImpl.getContainerList(ContainerServiceImpl.java:98)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    java.lang.reflect.Method.invoke(Method.java:498)
    org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:333)
    org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
    org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
    org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
    org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:282)
    org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
    org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
    com.sun.proxy.$Proxy33.getContainerList(Unknown Source)
    cn.com.ecict.controller.ContainerController.getContainerList(ContainerController.java:48)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    java.lang.reflect.Method.invoke(Method.java:498)
    org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205)
    org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:133)
    org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:97)
    org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827)
    org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738)
    org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:967)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:901)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
    org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:661)
    org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197)
    org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)

Note The full stack trace of the root cause is available in the server logs.

解决办法: 修改实体类UserBean,实现Serializable接口即可。

@Entity
@Table(name="users")
public class UserBean implements Serializable {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer  uid;
    //该字段不更新
    @Column(updatable=false)
    private String   username;
    private String   password;
    private String   email;
    private Integer  usertype;
    private String   identity;
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "lastlog")
    private Date     lastlog;
    private Integer  status;

    public UserBean(){}

    public UserBean(Integer uid, String username, String password, String email, Integer usertype, Date lastlog) {
        this.uid = uid;
        this.username = username;
        this.password = password;
        this.email = email;
        this.usertype = usertype;
        this.lastlog = lastlog;
    }

    @Override
    public String toString() {
        return "UserBean{" +
                "uid=" + uid +
                ", username='" + username + '\'' +
                ", password='" + password + '\'' +
                ", email='" + email + '\'' +
                ", usertype=" + usertype +
                ", lastlog=" + lastlog +
                '}';
    }

    public Integer getUid() {
        return uid;
    }

    public void setUid(Integer uid) {
        this.uid = uid;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public Integer getUsertype() {
        return usertype;
    }

    public void setUsertype(Integer usertype) {
        this.usertype = usertype;
    }

    public Date getLastlog() {
        return lastlog;
    }

    public void setLastlog(Date lastlog) {
        this.lastlog = lastlog;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public String getIdentity() {
        return identity;
    }

    public void setIdentity(String identity) {
        this.identity = identity;
    }
}

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

相关文章

来自专栏码匠的流水账

聊聊ribbon的retry

spring-cloud-netflix-ribbon-2.0.0.RELEASE-sources.jar!/org/springframework/cloud...

631
来自专栏青枫的专栏

【填大坑】关于Struts2中的 No result defined for action and result input 错误

配置好了struts.xml,也写好了Action,可是提交表单后就报 No result defined for action and result inpu...

1064
来自专栏大数据学习笔记

NoClassDefFoundError: org/hibernate/engine/transaction/spi/TransactionContext

1.问题 在整合Hibernate 5.2和spring4.3时出现了这个问题。 HTTP Status 500 – Internal Server Error...

5616
来自专栏一个会写诗的程序员的博客

《Springboot极简教程》MappingMongoConverter:Failed to convert from type [java.lang.String] to type [long]

Failed to convert from type [java.lang.String] to type [long] for value 'null'; ...

693
来自专栏linux驱动个人学习

ALSA声卡驱动的DAPM(一)-DPAM详解

最近使用tinymix 调试相应的音频通道,但是一直不知道音频通道的原理是什么。所以百度了一下,百度结果是与DPAM有关。 一、DAPM简介:  DAPM是Dy...

4246
来自专栏GIS讲堂

openlayers2渐变色渲染

在前文中,讲到了oL2中唯一值渲染的实现方式,在本文讲述ol2中渐变色渲染的实现方式。

732
来自专栏GIS讲堂

Openlayers中热力图的实现

Heatmap 是用来呈现一定区域内的统计度量,最常见的网站访问热力图就是以特殊高亮的形式显示访客热衷的页面区域和访客所在的地理区域的图示。Heatmap.j...

1083
来自专栏互联网软件技术

省市区联动

933
来自专栏Ryan Miao

国家语言,语言代码,locale id对应表

国家语言,语言代码,locale id对应表。比如 en_US对应的id为1033, 中文的locale=zh_CN,id=2052. LocaleLang...

1.3K7
来自专栏小樱的经验随笔

【BZOJ】初级水题列表——献给那些想要进军BZOJ的OIers(自用,怕荒废了最后的六月考试月,刷刷水题,水水更健康)

BZOJ初级水题列表——献给那些想要进军BZOJ的OIers 代码长度解释一切! 注:以下代码描述均为C++ RunID User Problem Res...

4029

扫码关注云+社区