This discussion is archived
14 Replies Latest reply: Jan 19, 2011 9:21 AM by 612864 RSS

EJB with Hibernate On Weblogic

paata_lom Newbie
Currently Being Moderated
Hi team,
It there any doc about it ?
i want to use hibernate as persistence layer for my ejb application.

Any Example also will be very useful.


____________________________
Regards,
Paata Lominadze
  • 1. Re: EJB with Hibernate On Weblogic
    dvohra21 Oracle ACE
    Currently Being Moderated
    Hibernate and entity ejb are both database persistence technologies. Use either of the two.
  • 2. Re: EJB with Hibernate On Weblogic
    paata_lom Newbie
    Currently Being Moderated
    Hi dvohra16
    I think you didn't understand what i need.
    For using hibernate as a persistence layer, i changed my persistence.xml like this:
    <persistence-unit name="reviewService"
              transaction-type="JTA">
              <provider>org.hibernate.ejb.HibernatePersistence</provider>
              <jta-data-source>java:/TestOracle151JNDI</jta-data-source>
              <properties>
                   <property name="hibernate.transaction.manager_lookup_class"
                        value="org.hibernate.transaction.WeblogicTransactionManagerLookup" />
              </properties>
         </persistence-unit>
    When my application going to deploy i got an error :
    Caused By: weblogic.deployment.EnvironmentException: Error processing persitence unit reviewService of module EJBModule.jar: Error instantiating the Persistence Provider class org.hibernate.ejb.HibernatePersistence of the PersistenceUnit reviewService: java.lang.ClassNotFoundException: org.hibernate.ejb.HibernatePersistence
    Where i must put hibernate jars ?
    I've created my domain named MgtBilling.


    ________________________
    Regards,
    Paata Lominadze
  • 3. Re: EJB with Hibernate On Weblogic
    164415 Oracle ACE
    Currently Being Moderated
    The documentation has a section on classloading that would have been helpful for you.

    http://download.oracle.com/docs/cd/E12839_01/web.1111/e13706/classloading.htm#i1096881

    >
    Adding JARs to the System Classpath

    WebLogic Server includes a lib subdirectory, located in the domain directory, that you can use to add one or more JAR files to the WebLogic Server system classpath when servers start up. The lib subdirectory is intended for JAR files that change infrequently and are required by all or most applications deployed in the server, or by WebLogic Server itself. For example, you might use the lib directory to store third-party utility classes that are required by all deployments in a domain. You can also use it to apply patches to WebLogic Server.

    The lib directory is not recommended as a general-purpose method for sharing a JARs between one or two applications deployed in a domain, or for sharing JARs that need to be updated periodically. If you update a JAR in the lib directory, you must reboot all servers in the domain in order for applications to realize the change. If you need to share a JAR file or Java EE modules among several applications, use the Java EE libraries feature described in Chapter 9, "Creating Shared Java EE Libraries and Optional Packages.">

    Placing the hibernate (and required dependencies) in this directory will make them available to both WLS and the applications to it.

    -steve-
  • 4. Re: EJB with Hibernate On Weblogic
    paata_lom Newbie
    Currently Being Moderated
    That is exactly what i need.
    Thank you very much.
    But i think that it will be more accurate to make some tools for package or library manager, like glassfish update manager.


    ______________________
    Regards,
    Paata Lominadze.
  • 5. Re: EJB with Hibernate On Weblogic
    dvohra21 Oracle ACE
    Currently Being Moderated
    Add the Hibernate JAR files to the WEB-INF/lib directory of the WAR file.
  • 6. Re: EJB with Hibernate On Weblogic
    447464 Newbie
    Currently Being Moderated
    it doesn't seem to be enough to have the jars in the web-inf\lib. My application can't find hibernate, nor can it find log4j's libraries!

    Since the application is already written, and makes use of some of Hibernate's specific calls (when using stored procs in the daos via the hibernate session), i'd like to continue to use hibernate 3.x with weblogic 10.x. Is this possible? If so, how do I setup my EAR (exploded) to make things easier?

    thanks a bunch.

    ERic
  • 7. Re: EJB with Hibernate On Weblogic
    612864 Explorer
    Currently Being Moderated
    Eric,
    If you want the benefits of JPA persistence with optional native ORM extensions - you could try EclipseLink - which is already shipped with WebLogic in the modules directory on the server. This will solve any classloading issues you have when running container managed deployments where you don't want to ship the JPA library with your EAR or create a shared library yourself.

    You will want the hibernate jars placed higher in the classpath in the modules directory off the main WebLogic install directory.

    I have detailed steps getting a standard JTA container managed JPA EntityManager running in an EAR via @PersistenceContext dependency injection on a @Stateless session bean on WebLogic in the following tutorial. The steps are all general to JPA with no native API but specifically implemented using EclipseLink as the JPA provider in persistence.xml. You should be able to follow these for Hibernate JPA if you wish to use this alternate JPA provider.

    http://wiki.eclipse.org/EclipseLink/Examples/JPA/WebLogic_Web_Tutorial

    thank you
    /Michael O'Brien
    http://www.eclipselink.org/
  • 8. Re: EJB with Hibernate On Weblogic
    RenévanWijk Oracle ACE
    Currently Being Moderated
    Deleted broken link
  • 9. Re: EJB with Hibernate On Weblogic
    447464 Newbie
    Currently Being Moderated
    It appears the error seems to be stemming from a couple of issues (based on other threads I've seen).

    1. I get an error when the container starts with:
    Hibernate Dialect must be explicitly set

    In my older OC4J 10.1.2 container, Spring was managing the JPA, so there was NOTHING in the persistence.xml file other than the jpa provider class and the lis of model classes, followed by an excluded unlisted classes. I had to modify the persistence.xml and copy some entries between my Spring applicationContext.xml's entry for the entityManager and this file.

    2. Secondly, I got the error:
    org.hibernate.QueryException: ClassNotFoundException: org.hibernate.hql.ast.HqlToken

    I was told this could be resolved by adding a weblogic-application.xml descriptor:
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <weblogic-application>
        <prefer-application-packages>
            <package-name>antlr.*</package-name>
        </prefer-application-packages>
    </weblogic-application>
    This appeared to solve the problem.

    3. I then received some other errors based on libraries included with the old OC4J but not included with WebLogic, such as the soap.jar and the SQLJ Runtime libraries.

    4. The next error I got was that it never prompted for login. For some reason, it didn't like: <url-pattern>/*.do</url-pattern>, but would work fine with: <url-pattern>*.do</url-pattern>. Why, I have no idea?

    5. I manually had to add the users and groups. I really liked the way oc4j could use a jazn-data.xml file to handle authentication. When I deploy from JDEV, it automatically creates the users and roles. Is there a way to make this easier than MANUALLY creating these users? I was using a DDONLY deployment from an exploded folder.

    6. The next problem was a missing data source. I had the data-sources.xml file there, but maybe that's not used? I got the error: Error looking up Data Source from Factory: While trying to lookup 'jdbc.eGovUserDS' didn't find subcontext 'jdbc'. Resolved ''. Is there a way to deploy with a descriptor that defines these data sources? I manually defined them in the server via the admin console.

    7. The reason I'm complaining more is that I'm a developer that uses to use the previous embedded oc4j 10.1.2. I never had an admin console to deal with in that version, and the deploymen descriptors took carfe of most of the issues/concerns.

    8. I then got the error: Root cause is: javax/persistence/Persistence.getPersistenceUtil()Ljavax/persistence/PersistenceUtil;
    java.lang.NoSuchMethodError: javax/persistence/Persistence.getPersistenceUtil()Ljavax/persistence/PersistenceUtil;

    I found a thread on this that it was caused by WebLogic 10.3.3 including a partial JPA 2 implementation, and then Hibernate's Validator trying to invoke a method on a class that was loaded already. I'm not sure what class has this?  Do you know how to search jars for classes and determine what would be the culprit? I resolved this temporarily by using a Hibernate Validator BETA release:

    hibernate-validator-4.2.0-20101202.092637-16.jar
    ejb3-persistence-1.0.2.GA.jar

    9. I ran into some other errors with commons logging and the xml parser as well with some class loading issues (I guess). I'll post those errors here as well.

    10. I tried to convert the application to Eclipselink, but it was not trivial. Like I said before, there was a number of stored procs (it was more than four). When I switched the provider, it had problems with my Dates (not using temporaly annotations), problems with my @ID annotations (had insert and update both false), problems with queries (I used subqueries with select 'x'), etc. I guess Hibernate was more lenient with this stuff?

    That's my long winded update.

    Thanks for any additional input you can provide.

    Eric
  • 10. Re: EJB with Hibernate On Weblogic
    447464 Newbie
    Currently Being Moderated
    In addition, I also had these issues:

    Using this…..
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <weblogic-application>
        <prefer-application-packages>
            <package-name>antlr.*</package-name>
            <!-- package-name>org.apache.commons.logging.*</package-name -->
            <!-- package-name>org.w3c.dom.*</package-name -->
        </prefer-application-packages>
    </weblogic-application>
    …. Resulted in this:

    An error occurred during activation of changes, please see the log for details.
    weblogic.application.ModuleException:
    loader constraint violation: loader (instance of weblogic/utils/classloaders/ChangeAwareClassLoader) previously initiated loading for a different type with name "org/apache/commons/logging/Log"


    Using this….
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <weblogic-application>
        <prefer-application-packages>
            <package-name>antlr.*</package-name>
            <package-name>org.apache.commons.logging.*</package-name>
            <!--package-name>org.w3c.dom.*</package-name-->
        </prefer-application-packages>
    </weblogic-application>
    
    ….. resulted in this:
    
    An error occurred during activation of changes, please see the log for details.
    weblogic.application.ModuleException:
    loader constraint violation: loader (instance of weblogic/utils/classloaders/ChangeAwareClassLoader) previously initiated loading for a different type with name "org/xml/sax/SAXParseException"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
  • 11. Re: EJB with Hibernate On Weblogic
    830935 Newbie
    Currently Being Moderated
    Another way of loading the hibernate classes in Weblogic is copying the jars into a folder in the weblogic server and modifying the setDomainEnv.cmd adding the jars to the classpath.

    An example using hibernate 3.3.2 that works, the line would be:
    @REM Hibernate jpa 1.0
    set EXT_PRE_CLASSPATH=%WL_HOME%\patches\jpa1\hibernate-entitymanager.jar;%WL_HOME%\patches\jpa1\commons-logging-1.1.1.jar;%WL_HOME%\patches\jpa1\log4j-1.2.16.jar;%WL_HOME%\patches\jpa1\javassist-3.9.0.GA.jar;%WL_HOME%\patches\jpa1\slf4j-log4j12-1.5.8.jar;%WL_HOME%\patches\jpa1\slf4j-api-1.5.8.jar;%WL_HOME%\patches\jpa1\jta-1.1.jar;%WL_HOME%\patches\jpa1\commons-collections-3.1.jar;%WL_HOME%\patches\jpa1\antlr-2.7.6.jar;%WL_HOME%\patches\jpa1\dom4j-1.6.1.jar;%WL_HOME%\patches\jpa1\hibernate-commons-annotations.jar;%WL_HOME%\patches\jpa1\hibernate-annotations.jar;%WL_HOME%\patches\jpa1\hibernate3.jar;%WL_HOME%\patches\jpa1\ejb3-persistence.jar;%EXT_PRE_CLASSPATH%
    In my case I have created a folder patches in the root of the wls and added this line
    @REM Hibernate jpa 2.0
    set EXT_PRE_CLASSPATH=%WL_HOME%\patches\jpa2\slf4j-jdk14-1.6.1.jar;%WL_HOME%\patches\jpa2\slf4j-api-1.6.1.jar;%WL_HOME%\patches\jpa2\jta-1.1.jar;%WL_HOME%\patches\jpa2\javassist-3.12.0.GA.jar;%WL_HOME%\patches\jpa2\dom4j-1.6.1.jar;%WL_HOME%\patches\jpa2\commons-collections-3.1.jar;%WL_HOME%\patches\jpa2\antlr-2.7.6.jar;%WL_HOME%\patches\jpa2\hibernate3.jar;%WL_HOME%\patches\jpa2\hibernate-jpa-2.0-api-1.0.0.Final.jar;%EXT_PRE_CLASSPATH%
    I am able to load the hibernate libraries but I receive the following error:

    java.lang.AbstractMethodError: weblogic.deployment.PersistenceUnitInfoImpl.getValidationMode()Ljavax/persistence/ValidationMode;
         at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:625)
         at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:73)
         at weblogic.deployment.PersistenceUnitInfoImpl.createEntityManagerFactory(PersistenceUnitInfoImpl.java:343)
         at weblogic.deployment.PersistenceUnitInfoImpl.createEntityManagerFactory(PersistenceUnitInfoImpl.java:323)
         at weblogic.deployment.PersistenceUnitInfoImpl.<init>(PersistenceUnitInfoImpl.java:125)


    I think it's thrown because the PersistenceUnitInfoImpl is done for JPA 1.0. Isn't it possible to use hibernate under JPA 2.0 with WL?

    Regards.

    Edited by: user9377265 on 13-Jan-2011 06:01
  • 12. Re: EJB with Hibernate On Weblogic
    447464 Newbie
    Currently Being Moderated
    I saw a few threads on this.

    Se Metalink Note: 1091853.1 (JPA Support in WebLogic Server)

    Also, for me the following fixed this issue:

    1. I pulled down a nightly build of the hibernate validator (awaiting one that fixes this as a CR):
    hibernate-validator-4.2.0-20101202.092637-16.jar
    (replacing hibernate-validator-4.0.0.GA.jar)

    2. I also replaced: ejb3-persistence-3.3.2.Beta1.jar with ejb3-persistence-1.0.2.GA.jar.

    Since I'm not the server admin, I'll just pass on these changes. However, ours works with hibernate now, and the classes are all in WEB-INF\lib.

    Thanks for the tips!
  • 13. Re: EJB with Hibernate On Weblogic
    830935 Newbie
    Currently Being Moderated
    Thanks for the answer

    I guess you are using JPA 1.0

    I would like to use the last version of hibernate with JPA 2.0

    Just in case it helps somebody I was able to make it work by comenting out the following lines in the org.hibernate.ejb.Ejb3Configuration class:
     * Commented out because wl persistenceunitinfo does not implement getValidationMode().
     * This would be used when a <validation-mode>auto</validation-mode> is set in persistence.xml but it can be set vendor-specifically
     * through <property name="javax.persistence.validation.mode" value="auto"/>
     */
    //                    else if ( info.getValidationMode() != null ) {
    //                         properties.put( AvailableSettings.VALIDATION_MODE, info.getValidationMode().name() );
    //                    }
     * Commented out because wl persistenceunitinfo does not implement getValidationMode().
     * This would be used when a <shared-cache-mode></shared-cache-mode> but hibernate does not implement it. It is required to use
     * another cache provider like ehcache.
     */                    
    //                    else if ( info.getSharedCacheMode() != null ) {
    //                         properties.put( AvailableSettings.SHARED_CACHE_MODE, info.getSharedCacheMode().name() );
    //                    }
    Edited by: user9377265 on 14-Jan-2011 03:17
  • 14. Re: EJB with Hibernate On Weblogic
    612864 Explorer
    Currently Being Moderated
    See the recent OTN post from 20110115 detailing the latest release of Oracle WebLogic Server and some retesting of the previous issues related to JSR-317 JPA 2.0 support below.
    Re: Deploy Hibernate based EAR file on Weblogic 10.3.3?

    The latest release of Oracle WebLogic Server has been available on OTN at the following location since 20110115.
    http://www.oracle.com/technetwork/middleware/weblogic/downloads/wls-main-097127.html

    This release provides support for JSR-317 JPA 2.0 container managed applications using the QWG8 patch or a manual prepending classpath change.

    In 10.3.3.0 you were required to use the FilteringClassLoader via the *<wls:prefer-application-packages>* addition to your application managed persistence unit - this workaround as well as the persistence.xml renaming one is now fully deprecated and not required in 10.3.4.0 for both application and container managed persistence contexts.
    As of 20110115 the 5 outstanding issues below look to be fixed by applying the http://download.oracle.com/docs/cd/E17904_01/web.1111/e13720/using_toplink.htm#EJBAD1309 patch for QWG8 or manually prepending to the WebLogic 10.3.4.0 server classpath.
    commEnv.cmd: line 67
    
    @rem Set BEA Home
    set BEA_HOME=C:\opt\wls1034r20110115
    @rem Enable JPA 2.0 functionality on WebLogic Server 10.3.4 with the following patch line for commEnv.cmd:67
    set PRE_CLASSPATH=%BEA_HOME%\modules\javax.persistence_1.0.0.0_2-0-0.jar;%BEA_HOME%\modules\com.oracle.jpa2support_1.0.0.0_2-0.jar
    A JPA 2.0 EE application using EclipseLink as the JPA2 persistence provider on WebLogic is detailed in the analysis section below
    1) JPA 2.0 XSD parsing - verified
    2) New JPA 2.0 schema elements like <shared-cache-mode>NONE</shared-cache-mode> - verified
    3) JPA 2.0 runtime API like a entityManager.getMetamodel(); call on the Servlet or Stateless session bean - verified
    4) JPA 2.0 weaving/instrumentation - this will require a more detailed lazy model and more debugging to fully verify
    5) Dependency Injection of a container managed JPA 2.0 entityManager on a EJB component like a stateless session bean - verified
    http://wiki.eclipse.org/EclipseLink/Development/JPA_2.0/weblogic#Enabling_JPA2_support
    OTN download
    http://www.oracle.com/technetwork/middleware/weblogic/downloads/wls-main-097127.html
    Patching
    http://download.oracle.com/docs/cd/E18476_01/doc.220/e18480/weblogicchap.htm
    Documentation
    http://download.oracle.com/docs/cd/E17904_01/web.1111/e13852/toc.htm
    Supported Oracle WebLogic Server Versions
    http://download.oracle.com/docs/cd/E15315_06/help/oracle.eclipse.tools.weblogic.doc/html/SupportedServerVersions.html
    TopLink JPA 2.0 Specific documentation/patching
    http://download.oracle.com/docs/cd/E17904_01/web.1111/e13720/using_toplink.htm#EJBAD1309
    EclipseLink Wiki: JPA 2.0 using EclipseLink on WebLogic analysis (XSD, Weaving, DI of @PersistenceContext)
    http://wiki.eclipse.org/EclipseLink/Development/JPA_2.0/weblogic#Enabling_JPA2_support

    thank you
    /Michael O'Brien
    http://www.eclipselink.org

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points