cancel
Showing results for 
Search instead for 
Did you mean: 

Using Hibernate3 with Java EE 5 Preview Edition

Former Member
0 Kudos

Is it possible to use Hibernate3 with the NetWeaver Java EE 5 Preview Edition?

My application's WAR includes Hibernate3 and its associated jars, notably antlr. When the application invokes a Hibernate3 query, the Hibernate code invokes antlr code (antlr.CharScanner.setTokenObjectClass()) which then fails with a ClassNotFound error for a Hibernate class which is in the Hibernate jar and is being loaded dynamically by antlr.

Upon investigation, it appears that this problem occurs because SAP bundles a version of antlr in sap.comtcantlr~runtime.jar. It seems that the failing antlr class is being loaded from this jar and not from the jar in my WAR. I suspect that this causes a classloader problem since the SAP bundled antlr jar is loaded by a classloader that doesn;t have visibility to the Hibernate jar.

I reviewed the SAP document on how to integrate Hibernate with NetWeaver and it indicated that the Hibernate libraries should by included in a SAP J2EE Library. It appears that the instructions for bundling these jars in a library are no longer valid as shared libraries are handled differently in Java EE 5 Preview Edition.

Is anyone successfully using Hibernate3 with the Java EE 5 Preview Edition? If so, did you have to do anything to integrate it into NetWeaver or was it sufficient to include its jars in your WAR? Did you use the Library Component feature to integrate Hibernate?

Reagrdling the classloading issue, it seems that a similar problem exists with BEA WebLogic. A response on a BEA Forum indicates that a similar Hibernate/antlr problem can be resolved by placing the antlr jar in WebLogic's PRE_CLASSPATH. Is there a similar conncept in NetWeaver?

Thanks,

Jerry

Accepted Solutions (1)

Accepted Solutions (1)

adrian_goerler
Employee
Employee
0 Kudos

Hi Jerry,

of course it is not acceptable that the antlr-version that is used by the Java EE server internally is exposed to a customer application. Customer applications should be able to the antlr version of their choice. We are working on a solution, which will be available in the next release.

Concerning the issue you are observing, you might try to patch Hibernate to fix the bug (I hope you have access to the Hibernate sources):

In

the antlr that is contained in the SAP Java EE 5 engine

, the method, in which the ClassNotFoundError that is bugging you is thrown, comes in two versions:

(1) antlr.CharScanner.setTokenObjectClass(<b>String name</b>)

and

(2)
antlr.CharScanner.setTokenObjectClass(<b>Class clazz</b>)

.

The method (1) uses the antlr-classloader and has no access to the hibernate class loader.

Unfortunately, Hibernate uses the method (1) in the HQL-Lexer (class org.hibernate.hql.ast.HqlLexer):

public void setTokenObjectClass(String cl) {
    // Ignore the token class name parameter, and use a specific token class.
    <b>super.setTokenObjectClass( HqlToken.class.getName() );</b>
}

You could try to replace this by

public void setTokenObjectClass(String cl) {
    // Ignore the token class name parameter, and use a specific token class.
    <b>super.setTokenObjectClass( HqlToken.class );</b>
}

.

I have not tried this out but if you should try it, please let us know if it helps.

Please note again, that you would have to compile the HqlLexer against the antlr contained in the Java EE 5 engine.

Best regards,

Adrian Görler

Message was edited by: Adrian Goerler

Former Member
0 Kudos

Adrain,

Your suggestion looks very promising. I tried a version of Hibernate3 that a colleague modifed per your suggestion and I'm no longer seeing the ClassNotFound error during our boot process. I'm now encountering another (apparently unrelated) error so I'm not able to fully exercise our Hibernate3 code yet. But it does look like our initial Hibernate3 queries are executing successfully now.

Thanks for the advice.

Jerry

Former Member
0 Kudos

Hi Adrian thanks for the information, I have a similar problem like the one Jerry has, but I´m testing with Netweaver 2004 and I got the same syntom , there is a workaround for 2004 besides modfiying Hibernate from source source, say , like copying hibernate jar files into a folder (is there a main folder for libraries) that could be invoke by the same classloader? Do you guys at SAP has a timeframe for this issue?

Enviroment (Testing), Netweaver 2004 SP18

According to Jerry ANTLR version for Preview 5 is 2.7.2, I´m testing with hibernate 3.1.3 with ANTLR 2.7.6rc1 , couldn´t figure out the version used by netweaver 2004, only the sike of the file is 350Kb.

Thxs,

Pedro Taborda

Vlado
Advisor
Advisor
0 Kudos

Hi Pedro,

This problem cannot happen with SAP NetWeaver 2004 and 2004s except if you explicitly add a reference from your application to the antlr library. In all other cases the Hibernate and ANTLR classes would be loaded from the jars bundled with your application.

Best regards,

Vladimir

Former Member
0 Kudos

Hi Vladimir, thanks for your response. Why do you say i can't happenwith a previous version of netweaver? The library antlr.jar is present in lib\ext and my exceptions is thrown just by trying to instantiatethe configuration class of hibernate which I understood triggers a series of constructors and classes loading. Can you suggest techniques or steps I may be able to isolate any class loading problems? Are there tools available ? perhaps some kind of monitors? My company has a support ticket with SAP because this problem. Or perhaps I'm missing something here in how class loading works in WebAS.

I use a servlet to initialize hibernate session factories using the init method and load at strat-up to 1

If I use this code an ClassDefNotFound is thrown

org.hibernate.cfg.Configuration cfgBdBDI_ECO = org.hibernate.cfg.Configuration();

if I comment the line the servlet works.

Thanks,

Pedro

I created the following deployment strategy:

Ped-core-1.0.0 J2EE Library

System-wide Constants

Ped-Modelo-1.0.0 J2EE Library

Hibernate Configuration Classes and configuration files

Ped-XI-BDMDMS-1.0.0 J2EE Library

Component (All Bussiness Logic is inside)

Ped-monitor-1.0.0 J2EE EAR (Web Project)

Responsible for initializes Hibernate Factories and also provides monitoring functionality

Ped-xi-bdidms-be-ear J2EE EAR (Java Proxy)

Queries JNDI and obtains references to the different resources needed and triggers the

component to perform the task.

Hibernate-3.1.3 J2EE Library

Hibernate Libraries

Apache Commons-1.0.0 J2EE Library

Apache Commons

JUnit J2EE Library

Unit Testing Framework

SAP WebAS Integration J2EE Library

Custom classes to integrate XA Transacctions with Hibernate and Log4J into SAP Logging API (Found source code in SDN)

hibernate-3.1.3

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE provider-descriptor SYSTEM "library.provider.dtd">

<provider-descriptor>

<display-name>Hibernate ORM Mapping Framework</display-name>

<component-name>org.hibernate</component-name>

<major-version>3</major-version>

<minor-version>1</minor-version>

<micro-version>3</micro-version>

<provider-name>hibernate.org</provider-name>

<references/>

<jars>

<jar-name>ant-1.6.5.jar</jar-name>

<jar-name>ant-antlr-1.6.5.jar</jar-name>

<jar-name>ant-junit-1.6.5.jar</jar-name>

<jar-name>ant-launcher-1.6.5.jar</jar-name>

<jar-name>ant-swing-1.6.5.jar</jar-name>

<jar-name>antlr-2.7.6rc1.jar</jar-name>

<jar-name>asm-attrs.jar</jar-name>

<jar-name>asm.jar</jar-name>

<jar-name>c3p0-0.9.0.jar</jar-name>

<jar-name>cglib-2.1.3.jar</jar-name>

<jar-name>cleanimports.jar</jar-name>

<jar-name>commons-collections-2.1.1.jar</jar-name>

<jar-name>commons-logging-1.0.4.jar</jar-name>

<jar-name>concurrent-1.3.2.jar</jar-name>

<jar-name>connector.jar</jar-name>

<jar-name>dom4j-1.6.1.jar</jar-name>

<jar-name>ehcache-1.1.jar</jar-name>

<jar-name>hibernate-3.1.3.jar</jar-name>

<jar-name>jaas.jar</jar-name>

<jar-name>jacc-1_0-fr.jar</jar-name>

<jar-name>jaxen-1.1-beta-7.jar</jar-name>

<jar-name>jboss-cache.jar</jar-name>

<jar-name>jboss-common.jar</jar-name>

<jar-name>jboss-jmx.jar</jar-name>

<jar-name>jboss-system.jar</jar-name>

<jar-name>jdbc2_0-stdext.jar</jar-name>

<jar-name>jgroups-2.2.8.jar</jar-name>

<jar-name>jta.jar</jar-name>

<jar-name>junit-3.8.1.jar</jar-name>

<jar-name>log4j-1.2.11.jar</jar-name>

<jar-name>oscache-2.1.jar</jar-name>

<jar-name>proxool-0.8.3.jar</jar-name>

<jar-name>swarmcache-1.0rc2.jar</jar-name>

<jar-name>syndiag2.jar</jar-name>

<jar-name>versioncheck.jar</jar-name>

<jar-name>xerces-2.6.2.jar</jar-name>

<jar-name>xml-apis.jar</jar-name>

</jars>

</provider-descriptor>

Vlado
Advisor
Advisor
0 Kudos

Hi Pedro,

I'm saying this because I know that in NW 2004 and 2004s the ANTLR version used by the server is not visible by default to deployed applications.

I'm sure that since you have logged a support ticket for this issue, it will be quickly (or is already?) resolved. If you want, you might tell me the ticket number and I'll also have a look at it.

Best regards,

Vladimir

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi All,

This is more then a year since the last reply on this thread. i am using CE7.1 SP3 and have the same problem.

Any one know what is the way to solve this problem. i am currently using the propeorty hibernate.query.factory_class = ..ClassicQueryTranslator... but i would like to use the new query engine.

any one can help?

Thanks,

Noam

ivo_simeonov
Explorer
0 Kudos

Hi Noam,

Try to pack the hibernate and ANTLR libraries in a "lib" subfolder of the ear. This will make them private libraries for the application and will solve the class loading issue.

Best Regards

Ivo Simeonov

Former Member
0 Kudos

I am running into similar issue related to JSF implementation of Myfaces vs

NetWeaver already packages Sun RF implementation.

My application is heavily dependent on myfaces jars. It is not working if I remove myfaces jars.

So, if I use NetWeaver CE 7.1 SP3, and copy Myfaces jars to .lib folder

(and create application-service.xml), would that resolve the issue?

I tried this scenario in NetWeaver CE 7.1 and it doesnt seem to work.

Any comments would be helpful.

thanks

nita

Former Member
0 Kudos

I am using MyFaces on my application and i just placed myfaces-api.jar and myfaces-impl.jar into the lib folder under EarContent folder of my EAR project and it works.

Also i followed this links:

/people/community.user/blog/2007/05/21/using-hibernate-in-sap-netweaver-composition-environment

/people/community.user/blog/2006/10/24/applications-and-shared-libraries

Before learning this method, i just recompiled antlr with hibernate using a different package name for antlr. So i have now a hibernate-with-antlr.jar. This makes hibernate reference the specific antlr i recompiled and not the antlr that came with SAP.

Former Member
0 Kudos

Hello Jerry,

I'm not sure if this might work. You could develop an own classloader and use this one to load the classes from antlr.jar that is packaged within your application's WAR. The intention is, that the antlr classes, provided by the J2EE engine, become invisible to your application and it uses the ones, that you loaded with your classloader.

Sun has a nice tutorial about writing one's own classloader: http://java.sun.com/developer/onlineTraining/Security/Fundamentals/magercises/ClassLoader/solution.h...

Kind regards, Lars

Former Member
0 Kudos

Hi Jerry!

> My application's WAR includes Hibernate3 and its

> associated jars, notably antlr. When the application

> invokes a Hibernate3 query, the Hibernate code

> invokes antlr code

> (antlr.CharScanner.setTokenObjectClass()) which then

> fails with a ClassNotFound error for a Hibernate

> class which is in the Hibernate jar and is being

> loaded dynamically by antlr.

We are aware of that problem and take it seriously because it endangers portability of existing Java EE applications. Currently we are working on a solution that will be provided with the next release. Anyway, thanks a lot for your feedback regarding that issue!

Best Regards,

Robin

Former Member
0 Kudos

Robin,

Any idea when we might see a fix for this issue? I'm just looking for a broad estimate (one month, three months, six months) if it's possible for you to provide one.

Thanks,

Jerry