10 Replies Latest reply on Jan 19, 2011 5:37 PM by obrienmi8

    Deploy Hibernate based EAR file on Weblogic 10.3.3?

      Hi all,
      Can anyone please let me know if it is possible to deploy Hibernate based EAR file on Weblogic 10.3.3?
      We are experiencing some problems with that, and I need to know if this is dead end or whether it suppose to work.
      We are NOT using Spring. Just plain JEE and Hibernate as JPA provider.

      Any tutorial for that? any check list?

      Thanks in advance,
        • 1. Re: Deploy Hibernate based EAR file on Weblogic 10.3.3?
          T, Hi,
          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.


          thank you
          /Michael O'Brien
          • 2. Re: Deploy Hibernate based EAR file on Weblogic 10.3.3?
            Hi Michael.
            Thanks for your reply.
            Just want to update you that we followed the tutorial and tried all the recommendations there in order to enable Hiberante 3.6 working on Weblogic 10.3.3 without any success.
            we still getting errors (depend on the scenario):
            1. java.lang.NoSuchMethodError: javax.persistence.spi.PersistenceUnitInfo.getSharedCacheMode()Ljavax/persistence/SharedCacheMode;
            2. Error instantiating the Persistence Provider class org.hibernate.ejb.HibernatePersistence of the PersistenceUnit TrivnetEJB: java.lang.ClassCastException: org.hibernate.ejb.HibernatePersistence cannot be cast to javax.persistence.spi.PersistenceProvider

            • 3. Re: Deploy Hibernate based EAR file on Weblogic 10.3.3?
              Hi, the 2 errors you are getting are the result of the following JPA 2 related classloading issues

              1. java.lang.NoSuchMethodError: javax.persistence.spi.PersistenceUnitInfo.getSharedCacheMode()Ljavax/persistence/SharedCacheMode;

              The tutorial is written for JPA 1.0 - if you are using the new <shared-cache-mode>NONE</shared-cache-mode> - this was introduced in JPA 2.0.
              See the following section on several currently unsupported scenarios getting JPA 2.0 API working on

              2. Error instantiating the Persistence Provider class org.hibernate.ejb.HibernatePersistence of the PersistenceUnit TrivnetEJB: java.lang.ClassCastException: org.hibernate.ejb.HibernatePersistence cannot be cast to javax.persistence.spi.PersistenceProvider

              Are your hibernate library jars in the system classloader classloader? A ClassCastException of this sort almost always means that the class is too low in the classloader tree (your EAR?) Verify they are in the modules directory and not your EAR for application managed persistence. For container managed persistence with your stateless session bean with @PersistenceContext(unitName="TrivneEJB") DI injection I suspect you are using - the pu should no longer get the CCE.

              Worst case (if you need JPA 2.0 design time API) just replace the JPA 1.0 spec jar with the 2.0 one (will have implications server-wide though).

              thank you
              • 4. Re: Deploy Hibernate based EAR file on Weblogic 10.3.3?
                We are having the same issue. Without modifying the modules libraries, we included the following jars into our boot classpath at the front of the shell script for starting the managed instance:


                This still caused an issue when the war is uploaded/deployed that it doesn't like the version="2.0" on the orm.xml and the persistence.xml.

                Is it necessary to modify the libraries in the modules directory? We aren't using ears so I can't create weblogic application xml files.

                • 5. Re: Deploy Hibernate based EAR file on Weblogic 10.3.3?
                  user161771 - oracle
                  Have you tried using a filtering classloader configured in weblogic.xml?
                  <?xml version="1.0" encoding="UTF-8"?>
                  <wls:weblogic-web-app xmlns:wls="http://xmlns.oracle.com/weblogic/weblogic-web-app" 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/web-app_2_5.xsd http://xmlns.oracle.com/weblogic/weblogic-web-app http://xmlns.oracle.com/weblogic/weblogic-web-app/1.1/weblogic-web-app.xsd">
                  • 6. Re: Deploy Hibernate based EAR file on Weblogic 10.3.3?
                    In order to deploy Hiberante successfully, we changed the Hibernate jar. Deleted 2 methods from an interface...
                    couldnt find any other way :(
                    The rumors are that WL 10.3.4 will solve the problem, anyone know where I can find it to download?

                    • 8. Re: Deploy Hibernate based EAR file on Weblogic 10.3.3?
                      Ya...my biggest problem is we aren't using ears.

                      We are using wars, but I don't want to taint them with weblogic specific configurations.

                      So I am looking primarily for a way to manipulate the boot classpath.

                      For right now, we just include antlr and the hibernate jpa jar in the classpath, but
                      we can't use version=2.0 in the orm.xml/persistence.xml, but we can still use JPA
                      2.0 features. Just get errors in the log files about the version.

                      • 9. Re: Deploy Hibernate based EAR file on Weblogic 10.3.3?
                        user161771 - oracle
                        WLS 10.3.4 was posted to OTN today.

                        Note that JPA 2.0 support for TopLink only requires a patch:

                        Perhaps there is a way to get Hibernate to work with this patch also, but I think the filtering classloader modifications via weblogic.xml is your best bet.
                        • 10. Re: Deploy Hibernate based EAR file on Weblogic 10.3.3?
                          Thank you for posting that WebLogic is now public - this is good news.
                          There is a large list of public OTN and EclipseLink wiki pages, bug/enhancement analysis comments and newsgroup entries that we are now able to discuss. A full review of all workarounds, updates to all WebLogic JPA 2.0 tutorial configurations and responses to all open WebLogic related JPA classloader and XSD validation issues is in order. I have prepared a list of these over the last year.
                          I'll post the links here as they become updated.

                          The main issues were JPA 2.0 XSD validation and JPA 2.0 container managed persistence unit injection.
                          In you were required to use the FilteringClassLoader via the *<wls:prefer-application-packages>* addition to your application managed persistence unit - this workaround is now deprecated and not required in for both application and container managed persistence contexts.
                          Specifically we will start retesting EE applications using a SSB injected @PersistenceContext container managed JTA transactional JPA 2.0 persistence units with/without JPA 2.0 XSD elements.

                          I verified the server and it is using SVN rev# *8635 from 6 Dec 2010* https://fisheye2.atlassian.com/changelog/eclipselink/?cs=8635
                          Essentially in order to enable JPA 2.0 functionality on WebLogic 10.3.4 shipped on 14 Jan 2011 - you apply the patch below or manually edit your server classpath to put the JPA 2.0 persistence specification API jar and the com.oracle.jpa2support_1.0.0.0_2-0.jar ahead of the other liibraries on the 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
                          Everything is shipped with WebLogic 10.3.4 but JPA 1.0 is enabled by default so that this JEE5 capable server is backwards compatible with JEE5/JPA1 out of the box. Without the above patch you will see the following.

                          <15-Jan-2011 5:58:40 o'clock PM EST> <Info> <Management> <BEA-141107> <Version: WebLogic Server Fri Dec 17 20:47:33 PST 2010 1384255 >
                          [EL Info]: 2011-01-15 18:06:38.082--ServerSession(48997950)--Thread(Thread[[ACTIVE] ExecuteThread: '3' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--EclipseLink, version: Eclipse Persistence Services - 2.1.2.v20101206-r8635
                          [EL Info]: 2011-01-15 18:06:38.082--ServerSession(48997950)--Thread(Thread[[ACTIVE] ExecuteThread: '3' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--Server:

                          We have the required bundles in the modules directory...
                          javax.persistence_1.0.0.0_2-0-0.jar (upgraded from 1-0-2)
                          org.eclipse.persistence_1.0.0.0_2-1.jar (upgraded from 2-0)

                          A very quick test of a JPA 2.0 container managed app with the following persistence.xml in the ejb.jar works as detailed below.

                          There are 3 issues we must check.
                          1) JPA 2.0 XSD parsing errors: as expected there are no more JPA 2.0 schema parsing issues.
                          2) New JPA 2.0 schema elements like the *<shared-cache-mode>NONE</shared-cache-mode>* element - this passes validation but we need to verify runtime functionality
                          3) JPA 2.0 runtime API like a entityManager.getMetamodel(); call on the Servlet or Statless session bean
                          4) JPA 2.0 weaving/instrumentation - Again we need to verify something like weaving of Entities contaiing lazy IndirectLists are weaved properly by the container.

                          Note: All testing in this post is on a WebLogic install out-of-the-box. The only modification I made was in creating a derby JTA global datasource "localJTA" on the server - and drop a container managed JPA 2.0 app as an EAR in the autodeploy directory on the default user domain.
                          <persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
                              <persistence-unit name="example" transaction-type="JTA">
                                  <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider> <!-- we will default to Kodo without specifying the provider -->
                                  <shared-cache-mode>NONE</shared-cache-mode><!-- shared-cache-mode must come after any class definitions (usually SE only) - the JPA schema is ordered -->
                                      <property name="eclipselink.target-server" value="WebLogic_10"/>
                                      <property name="eclipselink.target-database" value="Derby"/>            
                                      <property name="eclipselink.logging.level" value="FINEST"/>
                                      <!-- new for http://wiki.eclipse.org/EclipseLink/Examples/JPA/Logging#Server_Logging  -->
                                      <property name="eclipselink.logging.logger" value="DefaultLogger"/>
                                      <!-- turn off DDL generation after the model is stable -->            
                                      <!-- property name="eclipselink.ddl-generation" value="drop-and-create-tables"/>
                                      <property name="eclipselink.ddl-generation.output-mode" value="database"/-->
                          For 3) we get the following exception out of the box on a servlet if we do not apply the above mentioned patch below - because the container defaults to Java EE 5 functionality - or JPA 1.0

                          java.lang.NoSuchMethodError: javax/persistence/EntityManager.getMetamodel()Ljavax/persistence/metamodel/Metamodel;
                          at org.eclipse.persistence.example.jpa.server.weblogic.enterprise.presentation.FrontController.processGliderComm

                          or 3) The same exception if we try to run JPA 2.0 on the DI entityManager from the SSB in the EJB container classLoader
                          javax.ejb.EJBException: EJB Exception: : java.lang.NoSuchMethodError: javax/persistence/EntityManager.getMetamodel()Ljavax/persistence/metamodel/Metamodel;
                          +     at org.eclipse.persistence.example.jpa.server.business.ApplicationService.insertObjects(ApplicationService.java:66)+
                          +     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)+
                          +     at java.lang.reflect.Method.invoke(Method.java:597)+
                          +     at com.bea.core.repackaged.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:310)+
                          +     at $Proxy74.insertObjects(Unknown Source)+
                          +     at org.eclipse.persistence.example.jpa.server.business.ApplicationService_5ptwty_ApplicationServiceLocalImpl.__WL_invoke(Unknown Source)+

                          We also get the Kodo/OpenJPA provider when we attempt to weave.

                          +<openjpa-1.1.1-SNAPSHOT-r422266:965591 fatal user error> org.apache.openjpa.util.MetaDataException: "org.eclipse.persistence.example.jpa.server.business.Cell.id" declares generator name "EL_SEQUENCE_CELL", but uses the AUTO generation type. The only valid generator names under AUTO are "uuid-hex" and "uuid-string".+

                          +     at org.apache.openjpa.persistence.AnnotationPersistenceMetaDataParser.getGeneratedValueStrategy(AnnotationPersistenceMetaDataParser.java:1226)+

                          Therefore there is still a little bit of configuration required.

                          Enabling JPA2 support
                          1) install the QWG8 patch, or
                          2) manually add the com.oracle.jpa2support_1.0.0.0_2-0.jar ahead of the server classpath by following the instructions in the documentation at
                          or doing it manually by modifying the following line
                          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
                          The following code
                          public class ApplicationService implements ApplicationServiceLocal {
                              @PersistenceContext(unitName="example", type=PersistenceContextType.TRANSACTION)     
                              private EntityManager entityManager;
                              public boolean insertObjects(List<Cell> classes) {
                                  try {
                                      for(int i=0; i< classes.size(); i++) {
                                      System.out.println("JPA 2.0 Metamodel: " + entityManager.getMetamodel());           
                          ...prints out the JPA 2.0 EntityManager dependency injected into the SSB proxy for the life of the transaction in the function

                          JPA 2.0 Metamodel: MetamodelImpl@34817119 [ 5 Types: , 2 ManagedTypes: , 2 EntityTypes: , 0 MappedSuperclassTypes: , 0 EmbeddableTypes: ]+
                          +[EL Finer]: 2011-01-15 22:36:00.33--UnitOfWork(34913451)--Thread(Thread[[ACTIVE] ExecuteThread: '0' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--TX beforeCompletion callback, status=STATUS_ACTIVE+

                          You can see that when we debug the stateless session bean $Proxy that has our injected EntityManager...
                          this     ApplicationService_5ptwty_Impl  (id=11616)     
                               __WL_EJBContext     SessionEJBContextImpl  (id=11654)     
                               entityManager     $Proxy73  (id=11639)     
                                    h     TransactionalEntityManagerProxyImpl  (id=11638)     
                                         appName     "org.eclipse.persistence.example.jpa.server.weblogic.enterpriseEAR" (id=11513)     
                                         closeMethod     Method  (id=11663)     
                                         moduleName     "org.eclipse.persistence.example.jpa.server.weblogic.enterpriseEJB.jar" (id=11515)     
                                         persistenceUnit     PersistenceUnitInfoImpl  (id=11665)     
                                         persistenceUnitName     "org.eclipse.persistence.example.jpa.server.weblogic.enterpriseEAR#org.eclipse.persistence.example.jpa.server.weblogic.enterpriseEJB.jar#example" (id=11666)     
                                         queryMethods     HashSet<E>  (id=11668)     
                                         transactionAccessMethod     Method  (id=11669)     
                                         transactionalMethods     HashSet<E>  (id=11670)     
                                         txHelper     TransactionHelperImpl  (id=11523)     
                                         txRegistry     ServerTransactionManagerImpl  (id=11524)     
                                         unqualifiedPersistenceUnitName     "example" (id=11672)     
                          ...no longer complains about an unknown getMetamodel() JPA 2.0 method signature
                          Oracle WebLogic Server 11gR1 PatchSet 3 r20110115 at localhost [Oracle WebLogic Server]     
                               Java HotSpot(TM) Client VM[localhost:8453]     
                                    Daemon Thread [[ACTIVE] ExecuteThread: '20' for queue: 'weblogic.kernel.Default (self-tuning)'] (Running)     
                                    Daemon Thread [[ACTIVE] ExecuteThread: '18' for queue: 'weblogic.kernel.Default (self-tuning)'] (Suspended)     
                                         TransactionalEntityManagerProxyImpl.invoke(Object, Method, Object[]) line: 18     
                                         $Proxy59.getMetamodel() line: not available [local variables unavailable]     
                                         ApplicationService_5ptwty_Impl(ApplicationService).insertObjects(List<Cell>) line: 60     
                          ..               JdkDynamicAopProxy.invoke(Object, Method, Object[]) line: 204     
                                         $Proxy71.insertObjects(List) line: not available     
                                         ApplicationService_5ptwty_ApplicationServiceLocalImpl.__WL_invoke(Object, Object[], int) line: not available     
                                         SessionLocalMethodInvoker.invoke(BaseLocalObject, MethodDescriptor, Object[], int, String, Class<?>) line: 39     
                                         ApplicationService_5ptwty_ApplicationServiceLocalImpl.insertObjects(List) line: not available     
                                         FrontController.generateGlider(PrintWriter) line: 252     
                          ..               FrontController(HttpServlet).service(ServletRequest, ServletResponse) line: 820     
                                         StubSecurityHelper$ServletServiceAction.run() line: 227     
                          ..               ExecuteThread.run() line: 176     
                          arg1     Method  (id=11511)     
                               clazz     Class<T> (javax.persistence.EntityManager) (id=8312)     
                               name     "getMetamodel" (id=11543)     
                               returnType     Class<T> (javax.persistence.metamodel.Metamodel) (id=11545)     
                          For 4) Weaving is occuring as expected on either the JPA 1.0 or JPA 2.0 entities. We check this by either checking that our Entity is an instanceof org.eclipse.persistence.internal.weaving.PersistenceWeaved interface, or debug into the Entity and look for our bytcode instrumented weaved fields that start with _persistence*.  The question is - we need a weaved field or weaved function that was introduced for JPA 2.0
                          [4]     Cell  (id=11571)     
                               _persistence_fetchGroup     null     
                               _persistence_primaryKey     null     
                               _persistence_session     null     
                               _persistence_shouldRefreshFetchGroup     false     
                               aCellAttribute     null     
                               id     null     
                               left     null     
                               peers     HashSet<E>  (id=11572)     
                                    map     HashMap<K,V>  (id=11575)     
                          com.oracle.jpa2support_1.0.0.0_2-0.jar forensics
                          I had a look at the patch jar com.oracle.jpa2support_1.0.0.0_2-0.jar that WebLogic 10.3.4 ships with that allows installers to enable JPA 2.0 (JSR-317) support to superceed the default JPA 1.0 (JSR-220) support. It looks like the container proxy code for container managed EntityManagerFactory and EntityManager $Proxy objects has been updated so that a JPA 2.0 EntityManager $Proxy object get injected with the proper API level object via the InvocationHandlerFactory, FactoryInterceptor. The Query proxy has been updated as well. There is a fix for Kodo(OpenJPA) and OpenJPA related to the recent change and deprecation of certain functions of those providers. The EclipseLink JPA 2.0 provider (as the provider for TopLink) did not need weblogic changes beyond placing the JPA javax.peristence 2.0 specification jar higher on the classpath.

                          The root EclipseLink tracking bug is 334468
                          OTN download
                          Supported Oracle WebLogic Server Versions
                          TopLink JPA 2.0 Specific

                          see related
                          JPA 2: Reverify JPA 2.0 XSD support in persistence.xml on AM/CM app on WebLogic
                          JPA 2.0: Add WebLogic 10.3 configuration process to enable the JPA 2.0 library functionality - updated
                          http://en.wikipedia.org/wiki/Oracle_WebLogic_Server - updated
                          JPA: Add downloadable 60k weblogic.EAR to wiki page (outside of SVN) - reopened
                          JPA: support WebLogic introduction of new JPA MBean that changes the default JPA provider
                          JPA: Update tutorial wiki for WebLogic 10.3 to match the Oracle WebLogic 11g - assigned
                          To be answered
                          OTN Post: 11g Release 1 Patch Set 3 (WLS 10.3.4) - updated
                          11g Release 1 Patch Set 3 (WLS 10.3.4)
                          OTN Post: WebLogic 10.0 + JPA 2.0 = errors - updated
                          Re: WebLogic 10.0 + JPA 2.0 = errors
                          Deploy Hibernate based EAR file on Weblogic 10.3.3?
                          OTN Post: Default JPA provider for Weblogic Server 10.3.2 (11g) - updated
                          Default JPA provider for Weblogic Server 10.3.2 (11g)
                          OTN Post: Hibernate 3.6 Final (JPA 2.0) + WL 10.3.x :Unable to deploy sample appn - updated
                          Hibernate 3.6 Final (JPA 2.0) + WL 10.3.x :Unable to deploy sample appn
                          WebLogic 10.0 + JPA 2.0 = errors
                          OTN Post: EJB with Hibernate On Weblogic - updated
                          Re: EJB with Hibernate On Weblogic
                          OTN Post: OEPE 1.6 - Oracle WebLogic Server 11gR1 PatchSet 3 requres WLS 10.3.4 - answered
                          OEPE 1.6 - Oracle WebLogic Server 11gR1 PatchSet 3 requres WLS 10.3.4
                          OTN Post: EJB with Hibernate On Weblogic - updated
                          Re: EJB with Hibernate On Weblogic
                          OTN Post: OpenJPA_2.0 NoSuchMethod error (getValidationMode()) - updated
                          OpenJPA_2.0 NoSuchMethod error (getValidationMode())
                          JPA 2.0 features used on WebLogic even if they are not available at runtime - notified
                          Option to enable JPA 2.0 for dev WebLogic - notified
                          False-positive error badge on project with JPA targeting WebLogic - notified
                          Giving up on Hibernate (for now), trying EclipseLink...
                          Eclipselink 2.0 + WebLogic 10 => No joy (Unable to get Eclipse link 2.0 working with WebLogic 10) - answered
                          eclipselink-users Problem of eclipselink upgrade (2.0.2) - WebLogic - answered
                          Re: EclipseLink + JPA 2 in Weblogic 10.3.0
                          http://dev.eclipse.org/mhonarc/lists/eclipselink-users/msg04375.html - answered below
                          Re: eclipselink-users Problems with Eclipselink 2 (JPA 2.0) & WebLogic 10,
                          [eclipselink-users] Problems with Eclipselink 2 (JPA 2.0) & WebLogic 10 - answered
                          To be Deprecated
                          JPA 2: Reverify JPA 2.0 XSD support in persistence.xml on AM/CM app on WebLogic
                          JPA 2.0: Add WebLogic 10.3 configuration process to enable the JPA 2.0 library functionality
                          WebLogic 10.3 availability?

                          / Michael O'Brien