Hibernate exception _$$_javassist_0 cannot be cast to javassist.util.proxy.Proxy

前端 未结 14 1003
伪装坚强ぢ
伪装坚强ぢ 2020-12-05 09:33

Hello I am using developnig java web application and I am getting the next exception when I am trying to fetch data using hibernate

java.lang.ClassCastExcept         


        
相关标签:
14条回答
  • 2020-12-05 10:08

    While only partially related to your question, I wanted to post this somewhere to help out anyone who may come across this problem when using SpringMVC, Hibernate, and Apache Tiles.

    I was getting this exception when I had org.apache.tiles tiles-extras listed as a dependency. Tiles-extras and hibernate-core have different versions of javassist listed as a dependency. By adding the following to my pom.xml file, I was able to fix the error.

    <dependency>
        <groupId>org.apache.tiles</groupId>
        <artifactId>tiles-extras</artifactId>
        <version>3.0.5</version>
        <exclusions>
            <exclusion>
                <artifactId>javassist</artifactId>
                <groupId>jboss</groupId>
            </exclusion>
        </exclusions>
    </dependency>
    
    0 讨论(0)
  • 2020-12-05 10:08

    I have been using 4.2.8-Final version of hibernate and was having this issue and went through the below answers/suggestions earlier. Here is the sequence of events I made - To get rid of the issue with 4.2.8-Final, was using "parent classes last" class loader approach in Websphere. Recently when the project grew in size (by having more hibernate related jar flavors), started to get the same issue.

    Finally excluded the "javassist" from hibernate

    <dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-core</artifactId>
    <version>${hibernate.version}</version>
    <exclusions>
        <exclusion>
            <groupId>org.javassist</groupId>
            <artifactId>javassist</artifactId>
        </exclusion>
    </exclusions>
    

    and added

    <dependency>
    <groupId>org.javassist</groupId>
    <artifactId>javassist</artifactId>
    <version>3.18.1-GA</version> 
    

    Even this didn't resolve the problem completely (still I had to use 'parent last' class loader approach with hibernate to get rid of the issue.

    Finally I downgraded hibernate version from 4.2.8-Final to 4.2.7-Final and the issue is solved (I need not change my class loader preference in websphere admin console as parent last anymore)

    Not exactly sure what change in 4.2.8 Hibernate is causing this issue. Curious to know.

    0 讨论(0)
  • 2020-12-05 10:09

    Fixed by changing dependency in my pom.xml to older version 4.3.4.Final Error was in 4.3.4.Final version changed to 4.2.7.Final

    Do not think it is the best solution but I have not found any other.

    0 讨论(0)
  • 2020-12-05 10:14

    It looks that Weblogic itself contains javaassist older, than your application has. It can be fixed in application descriptor, weblogic.xml or weblogic-application.xml. Just add

    <prefer-application-packages>
        <package-name>javassist</package-name>        
    </prefer-application-packages>
    

    into root config element.

    Btw, you can check such conflicts using Weblogic Classloader Analysis Tool - it can be accessed on /wls-cat context path of your server.

    0 讨论(0)
  • 2020-12-05 10:15

    I use with hibernate 4.3.5.Final and have similar problem with javassist, the problem is that javassist is missing, and you can get the latest from the Maven repositorty.

    <dependency>
        <groupId>org.javassist</groupId>
        <artifactId>javassist</artifactId>
        <version>3.18.1-GA</version> 
    </dependency>
    

    In later editions it is fixed again

    With this all works in my case,

    0 讨论(0)
  • 2020-12-05 10:17

    I had a similar issue with javassist. I use the following dependencies in pom.xml file -

    <org.hibernate.version>4.2.15.Final</org.hibernate.version>
    <org.pentaho.di>6.0.1.0-386</org.pentaho.di>
    
    
    <dependency>
                <groupId>pentaho-kettle</groupId>
                <artifactId>kettle-core</artifactId>
                <version>${org.pentaho.di}</version>
                <exclusions>
                    <exclusion>
                        <artifactId>xercesImpl</artifactId>
                        <groupId>xerces</groupId>
                    </exclusion>
                    <exclusion>
                        <artifactId>javassist</artifactId>
                        <groupId>javassist</groupId>
                    </exclusion>
                </exclusions>
            </dependency>
    
    
    
        <dependency>
                <groupId>org.hibernate</groupId>
                <artifactId>hibernate-ehcache</artifactId>
                <version>${org.hibernate.version}</version>
                <exclusions>
                    <exclusion>
                        <artifactId>slf4j-api</artifactId>
                        <groupId>org.slf4j</groupId>
                    </exclusion>
                    <exclusion>
                        <artifactId>ehcache-core</artifactId>
                        <groupId>net.sf.ehcache</groupId>
                    </exclusion>
                </exclusions>
            </dependency>
    
    +- org.hibernate:hibernate-ehcache:jar:4.2.15.Final:compile
    [INFO] |  +- org.jboss.logging:jboss-logging:jar:3.1.0.GA:compile
    [INFO] |  \- org.hibernate:hibernate-core:jar:4.2.15.Final:compile
    [INFO] |     +- antlr:antlr:jar:2.7.7:compile
    [INFO] |     +- (org.jboss.logging:jboss-logging:jar:3.1.0.GA:compile - omitted for duplicate)
    [INFO] |     +- (dom4j:dom4j:jar:1.6.1:compile - omitted for duplicate)
    [INFO] |     +- org.javassist:javassist:jar:3.18.1-GA:compile
    

    Hibernate contains the appropriate version, hence removing it from pentaho-core I found the dependency tree using-

    mvn dependency:tree -Dverbose >> C:\pipeout2.txt
    
    0 讨论(0)
提交回复
热议问题