Hibernate报错: java.lang.ClassCastException: pojo.Student_$$_javassist_0 cannot be cast to javassist.util.proxy.Proxy

今天滴滴滴在温故关于Hibernate的查询语法:Query的 list() 与iterate() 时
编写测试代码报错:javassist_0 cannot be cast to javassist.util.proxy.Proxy

hibernate_javassist报错

查阅很多资料 大概有三种解决方法:

1.在web.xml中配置 filter

<filter>
       <filter-name>openSessionInView</filter-name>
      <filter- class>             org.springframework.orm.hibernate5.support.OpenSessionInViewFilter
      </filter-class>
</filter>

<filter-mapping>
     <filter-name>openSessionInView</filter-name>
     <url-pattern>/*</url-pattern>
</filter-mapping>

这个方法明显不适用滴滴滴

2.查看项目中是否有冲突的jar包

冲突jar

3.在hbm文件中,指定懒加载为false,不指定默认为true

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
         "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">

<hibernate-mapping package="pojo">
         <class name="Student" table="t_student" lazy="false">
         <id name="id" column="tid">
              <generator class="native"/>
        </id>

    //省略字段
</hibernate-mapping>

滴滴滴用第三种方案解决了报错