Tuesday, October 9, 2012

ClassNotFoundException: org.hibernate.hql.ast.HqlToken

When using Hibernate to read from a Database using Weblogic 10 and Springframework 2.5.6, I encountered the following error:

ClassNotFoundException: org.hibernate.hql.ast.HqlToken

The reason for this is that it by default will use Weblogic's default classloader to load the antlr jar file and doesn't use the version included within your .war file.

To solve this you need to wrap your .war in an ear file and within the META-INF/weblogic-application.xml file within you .ear file include the following:
 <prefer-application-packages>
    <package-name>antlr.*</package>
 </prefer-application-packages>
 

This should resolve this issue.