1 Reply Latest reply on Jan 4, 2012 3:14 PM by Peter Fry

    application managed entity manager / JAX-WS

    Peter Fry Newbie

      I have an application packaged in an ear file deploying to JBoss As 7.1 beta1b

       

      myEAR.ear/META-INF/jboss-deployment-structure.xml

      myEAR.ear/META-INF/application.xml

      myEAR.ear/myEjb.jar

      myEAR.ear/myWar.war

      myEAR.ear/lib/common.jar

      myEAR.ear/lib/antlr-2.7.6.jar

      myEAR.ear/lib/cglib-2.2.jar

      myEAR.ear/lib/commons-collections-3.1.jar

      myEAR.ear/lib/dom4j-1.6.1.jar

      myEAR.ear/lib/hibernate3.jar

      myEAR.ear/lib/javassist-3.12.0.GA.jar

      myEAR.ear/lib/myModel.jar

      myEAR.ear/lib/myModel.jar/META-INF/persistence.xml

       

      The application starts up without any errors, there are a few warnings but I don't think they are affecting things. The JAX-WS webservices deploy and can be called, the SLSB's in myEjb.jar can be called from a separate war file deployment and the entities are being mapped. The problem seems to occur when the web services calls into a library jar file which has helper classes to create application managed entity manager instances. A class cast exception occurs when retrieving/using the dialect which suggests to me that two different classloaders are in action. The deployment structure file attempts to ensure that hibernate 3 is used but I am not sure if this is working as the first few log messages refer to Hibernate Core {4.0.0.CR6} even though the stack trace includes lines for hibernate3.jar . Note that the JPA is being used directly from the web service classes, no EJBs are involved.

       

      The jboss-deployment-structure.xml is attached.

      The persistence.xml is attached

       

      09:25:08,203 INFO  [org.hibernate.annotations.common.Version] (http-127.0.0.1-127.0.0.1-8080-1) HCANN000001: Hibernate Commons Annotations {4.0.0.CR2}

      09:25:08,208 INFO  [org.hibernate.Version] (http-127.0.0.1-127.0.0.1-8080-1) HHH000412: Hibernate Core {4.0.0.CR6}

      09:25:08,208 INFO  [org.hibernate.cfg.Environment] (http-127.0.0.1-127.0.0.1-8080-1) HHH000206: hibernate.properties not found

      09:25:08,210 INFO  [org.hibernate.cfg.Environment] (http-127.0.0.1-127.0.0.1-8080-1) HHH000021: Bytecode provider name : javassist

      09:25:08,713 INFO  [org.hibernate.dialect.Dialect] (http-127.0.0.1-127.0.0.1-8080-1) Using dialect: org.hibernate.dialect.Oracle10gDialect

      09:25:08,715 ERROR [org.jboss.ws.common.invocation.InvocationHandlerJAXWS] (http-127.0.0.1-127.0.0.1-8080-1) Method invocation failed with exception: null: java.lang.reflect.Invoca

              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [:1.6.0_23]

              at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) [:1.6.0_23]

              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [:1.6.0_23]

              at java.lang.reflect.Method.invoke(Method.java:597) [:1.6.0_23]

              at org.jboss.ws.common.invocation.AbstractInvocationHandlerJSE.invoke(AbstractInvocationHandlerJSE.java:111)

              at org.jboss.wsf.stack.cxf.JBossWSInvoker._invokeInternal(JBossWSInvoker.java:169)

              at org.jboss.wsf.stack.cxf.JBossWSInvoker.invoke(JBossWSInvoker.java:117)

              at org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:58)

              at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441) [:1.6.0_23]

              at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303) [:1.6.0_23]

              at java.util.concurrent.FutureTask.run(FutureTask.java:138) [:1.6.0_23]

              at org.apache.cxf.workqueue.SynchronousExecutor.execute(SynchronousExecutor.java:37)

              at org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:106)

              at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:263)

              at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)

              at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:206)

              at org.jboss.wsf.stack.cxf.RequestHandlerImpl.handleHttpRequest(RequestHandlerImpl.java:91)

              at org.jboss.wsf.stack.cxf.transport.ServletHelper.callRequestHandler(ServletHelper.java:174)

              at org.jboss.wsf.stack.cxf.CXFServletExt.invoke(CXFServletExt.java:87)

              at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:184)

              at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doPost(AbstractHTTPServlet.java:107)

              at javax.servlet.http.HttpServlet.service(HttpServlet.java:754) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:]

              at org.jboss.wsf.stack.cxf.CXFServletExt.service(CXFServletExt.java:135)

              at org.jboss.wsf.spi.deployment.WSFServlet.service(WSFServlet.java:140) [jbossws-spi-2.0.0.CR1.jar:]

              at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:]

              at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.3.Final.jar:]

              at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.3.Final.jar:]

              at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [jbossweb-7.0.3.Final.jar:]

              at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [jbossweb-7.0.3.Final.jar:]

              at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50) [jboss-as-jpa-7.1.0.Beta1b.jar:]

              at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:151) [jboss-as-web-7.1.0.Beta1b.jar:]

              at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) [jbossweb-7.0.3.Final.jar:]

              at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.3.Final.jar:]

              at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.3.Final.jar:]

              at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:362) [jbossweb-7.0.3.Final.jar:]

              at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [jbossweb-7.0.3.Final.jar:]

              at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671) [jbossweb-7.0.3.Final.jar:]

              at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930) [jbossweb-7.0.3.Final.jar:]

              at java.lang.Thread.run(Thread.java:662) [:1.6.0_23]

      Caused by: uk.co.mycompany.model.exception.EntityManagerRetrievalException: uk.co.mycompany.common.memoizer.MemoizerException: java.util.concurrent.ExecutionException: javax.persistenc

              at uk.co.mycompany.model.entitymanager.EntityManagerHelper.getEntityManagerByClientRef(EntityManagerHelper.java:108) [common.jar:]

              at uk.co.mycompany.webservices.WebServiceHelper.getSomething(WebServiceHelper.java:1027) [classes:]

              at uk.co.mycompany.webservices.WebServiceHelper.memberHasSomthing(WebServiceHelper.java:886) [classes:]

              at uk.co.mycompany.webservices.security.myapp.AWebService.verifySomething(AuthenticationWebService.java:263) [classes:]

              at uk.co.mycompany.webservices.security.myapp.AWebService.method1(AWebService.java:182) [classes:]

              ... 39 more

      Caused by: uk.co.mycompany.common.memoizer.MemoizerException: java.util.concurrent.ExecutionException: javax.persistence.PersistenceException: [PersistenceUnit: myDatabase] Unabl

              at uk.co.mycompany.common.memoizer.Memoizer.compute(Memoizer.java:68) [common.jar:]

              at uk.co.mycompany.model.entitymanager.EntityManagerHelper.getEntityManagerFactory(EntityManagerHelper.java:165) [common.jar:]

              at uk.co.mycompany.model.entitymanager.EntityManagerHelper.getEntityManagerByClientRef(EntityManagerHelper.java:102) [common.jar:]

              ... 43 more

      Caused by: java.util.concurrent.ExecutionException: javax.persistence.PersistenceException: [PersistenceUnit: myDatabase] Unable to build EntityManagerFactory

              at java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:222) [:1.6.0_23]

              at java.util.concurrent.FutureTask.get(FutureTask.java:83) [:1.6.0_23]

              at uk.co.mycompany.common.memoizer.Memoizer.compute(Memoizer.java:60) [common.jar:]

              ... 45 more

      Caused by: javax.persistence.PersistenceException: [PersistenceUnit: myDatabase] Unable to build EntityManagerFactory

              at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:914) [hibernate3.jar:]

              at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:890) [hibernate3.jar:]

              at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:56) [hibernate3.jar:]

              at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:63) [hibernate-jpa-2.0-api-1.0.1.Final.jar:]

              at uk.co.mycompany.model.entitymanager.EntityManagerFactoryRetriever.compute(EntityManagerFactoryRetriever.java:48) [common.jar:]

              at uk.co.mycompany.model.entitymanager.EntityManagerFactoryRetriever.compute(EntityManagerFactoryRetriever.java:25) [common.jar:]

              at uk.co.mycompany.common.memoizer.Memoizer$1.call(Memoizer.java:46) [common.jar:]

              at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303) [:1.6.0_23]

              at java.util.concurrent.FutureTask.run(FutureTask.java:138) [:1.6.0_23]

              at uk.co.mycompany.common.memoizer.Memoizer.compute(Memoizer.java:55) [common.jar:]

              ... 45 more

      Caused by: org.hibernate.HibernateException: Could not instantiate dialect class

              at org.hibernate.service.jdbc.dialect.internal.DialectFactoryImpl.constructDialect(DialectFactoryImpl.java:82)

              at org.hibernate.service.jdbc.dialect.internal.DialectFactoryImpl.buildDialect(DialectFactoryImpl.java:64)

              at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:142)

              at org.hibernate.service.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:75)

              at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:165)

              at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:139)

              at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:71) [hibernate3.jar:]

              at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2259) [hibernate3.jar:]

              at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2255) [hibernate3.jar:]

              at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1724) [hibernate3.jar:]

              at org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:76) [hibernate3.jar:]

              at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:905) [hibernate3.jar:]

              ... 54 more

      Caused by: java.lang.ClassCastException: org.hibernate.dialect.Oracle10gDialect cannot be cast to org.hibernate.dialect.Dialect

              at org.hibernate.service.jdbc.dialect.internal.DialectFactoryImpl.constructDialect(DialectFactoryImpl.java:73)

        • 1. Re: application managed entity manager / JAX-WS
          Peter Fry Newbie

          I managed to get this to work by

           

          1) Upgrading to JBoss AS 7.1 CR1b

          2) Using the default JPA provider (Hibernate 4).

          3) Making the separate war file deployments dependent on deployment.myapplication.ear via the mywebapp.war/META-INF/MANIFEST.MF with the significant line being:

           

            Dependencies: javax.api,deployment.altair.ear

           

          The general from of the jboss-deployment-structure.xml ( myapplication.ear/META-INF/jboss-deployment-structure.xml) used is

           

          <jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.0">

           

          <ear-subdeployments-isolated>false</ear-subdeployments-isolated>

           

          <deployment>

           

           

          <dependencies>

           

          <module name="org.hibernate" slot="main"/>

           

          <module name="org.slf4j"/>

           

          <module name="com.oracle.ojdbc6"/>

           

          <module name="org.jboss.ironjacamar.jdbcadapters"/>

           

          <module name="org.hibernate.envers"/>

           

          </dependencies>

           

          </deployment>

           

          <sub-deployment name="biz.jar">

           

           

          <dependencies>

           

          <module name="org.hibernate" slot="main"/>

           

          <module name="org.slf4j"/>

           

          <module name="com.oracle.ojdbc6"/>

           

          <module name="org.jboss.ironjacamar.jdbcadapters"/>

           

          <module name="org.hibernate.envers"/>

           

          </dependencies>

           

          </sub-deployment>

           

           

          </

          jboss-deployment-structure>

           

           

          The ironjacamar dependency was required for something else, the envers depenency was required to get Hibernate 4 to work. The org.hibernate dependency was required to be explicit. Defining the hibernate dependency ovbiously means that no hibernate jars need to be placed in the lib directory of the ear archive. I may update this reply if it was only biz.jar that needed the dependencies to be defined and whether the ear-subdeployments-isolated needs to specified.

           

          The form of the persistence.xml was as follows:

           

          <?xml version="1.0" encoding="UTF-8"?>
          <persistence 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_1_0.xsd"
          version="1.0">
          <persistence-unit name="myDatabase"
            transaction-type="JTA">
            <jta-data-source>java:/MyDS</jta-data-source>
            <class>uk.co.mycompany.model.AccessUser</class>
            <properties>
             <property name="hibernate.hbm2ddl.auto" value="none" />
             <property name="hibernate.show_sql" value="true" />
             <property name="hibernate.format_sql" value="true" />
             <property name="hibernate.cache.use_second_level_cache" value="false" />
             <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup"/>
            </properties>
          </persistence-unit>
          </persistence>

           

           

          Things that did NOT work included

           

          1) moving my shared jars out of the lib folder of the ear file into a proper jboss module structure.

          2) putting a copy of your persistence.xml file into the WEB-INF/classes directory of a WAR file(s)

          3) trying to using Hibernate 3 was not unhelpful (probably mistakes on my side).