Monday, September 24, 2007

Hibernate, antlr and Class loading issues

Hibernate uses HQL(Hibernate Query Language) for generating Object-Oriented queries.  Hence for this purposes ships a specific version of antlr.jar along with the Hibernate. Most of the App servers use antlr to generate the Query Language for the CMP beans. In this case, it is quite possible that the two versions of antlr are different. The difference in versions kicks in some of the exception messages when you try to access the application. Most of the time, the exception is reported in the HQLToken class.

In some cases, ClassNotFound/NoClassDef exceptions are also reported as the global library file is trying to access the Applications WEB-INF/classes or WEB-INF/lib folders.

To resolve it, the easiest option is to remove the version shipped with App Server(Please note that most of the App Server support personnel refuse to assist if the folder structure/folders are altered in the server installation).  In case you are not using any components that use Container Managed Persistence, the above work around works fine.  The problems kick in when any of your component tries to use Container Managed Persistence. Also, to make sure that you get proper support from your App Server vendor, the above approach should not be followed.

So what should be done?

To fix the issues, the class load/search/scope functionalty of the App server needs to be modified. The classes in the WEB-INF/classes or WEB-INF/lib folders should be loaded/searched prior to the global ones.

Fortunately most of the Application servers provide a way to change to such classloading functionality. Following is the consolidated list for the App Servers:

Pramati Server:

Add the following tag after <module-name>  in the generated pramati-j2ee-server.xml file for the application under the <web-module> element:

<prefer-deployed-web-classes>true</prefer-deployed-web-classes>

OC4J:
http://download.oracle.com/docs/cd/B25221_04/web.1013/b14433/classload.htm#CIHFABFI

WebLogic:
http://edocs.bea.com/wls/docs81/programming/classloading.html#1082452

Websphere:
http://publib.boulder.ibm.com/infocenter/wasinfo/v5r0/topic/com.ibm.websphere.base.doc/info/aes/ae/crun_classload.html

JBoss:
http://wiki.jboss.org/wiki/Wiki.jsp?page=ClassLoadingConfiguration

No comments: