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
In my case problem was that there were two javassist
libraries in classpath. One from org.hibernate
and other from org.apache.struts.xwork
. Solved by removing latter.
Check your return type T
or List<T>
of results
Resolved issue for weblogic based spring-hibernate-jpa application. The class cast exception occurs because of conflicting jars of web logic server and javassist jar. Add the javassist-3.18.0-ga.jar or higher version into your class path and then add below lines of code into your weblogic-application.xml file and it should resolve your issue.
<wls:prefer-application-packages>
<wls:package-name>javassist.*</wls:package-name>
</wls:prefer-application-packages>
I had the same issue when using hibernate + titles. Solved by excluding javassist from tiles-extras:
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-extras</artifactId>
<version>3.0.5</version>
<exclusions>
<exclusion>
<groupId>jboss</groupId>
<artifactId>javassist</artifactId>
</exclusion>
</exclusions>
</dependency>
If you are deploying your hibernate based application on the weblogic server or similar, you are going to have an earlier version of javassist jar available inside the modules folder of the server. This would cause the conflict talked about in the earlier answers where you may end up in having more than one jars in the classpath.
specifically for weblogic add following in your weblogic-application.xml
add package-name javaassist.* to ensure that latest is picked up.
<?xml version="1.0" encoding="UTF-8"?>
<wls:weblogic-application
xmlns:wls="http://www.bea.com/ns/weblogic/weblogic-application"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/javaee_5.xsd http://www.bea.com/ns/weblogic/weblogic-application http://www.bea.com/ns/weblogic/weblogic-application/1.0/weblogic-application.xsd">
<wls:ejb>
<wls:start-mdbs-with-application>false
</wls:start-mdbs-with-application>
</wls:ejb>
<wls:prefer-application-packages>
<wls:package-name>antlr.*</wls:package-name>
<wls:package-name>org.apache.commons.*</wls:package-name>
<wls:package-name>org.apache.xmlbeans.*</wls:package-name>
<wls:package-name>org.springframework.*</wls:package-name>
<wls:package-name>org.hibernate.*</wls:package-name>
<wls:package-name>org.joda.*</wls:package-name>
<wls:package-name>javax.persistence.*</wls:package-name>
<wls:package-name>com.google.*</wls:package-name>
<wls:package-name>com.ibm.icu.*</wls:package-name>
<wls:package-name>org.apache.axiom.*</wls:package-name>
<wls:package-name>javassist.*</wls:package-name>
</wls:prefer-application-packages>
</wls:weblogic-application>
Like anquegi has already commented. You have a lib conflict. Back hibernate to 4.2.7.Final will not solve your lib conflict.
Run mvn dependency:tree -Dverbose
and look to javassist different versions. In my case, I need to exclude javassist from Hibernate dependencies.
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate.version}</version>
<exclusions>
<exclusion>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>${hibernate.version}</version>
<exclusions>
<exclusion>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
</exclusion>
</exclusions>
</dependency>
This may help others in to future.