9 Replies Latest reply on Jan 5, 2012 6:43 AM by stephan972

    JBoss 5.1 GA + JPA 2

    Rajan Desai Newbie

      Can some one please help me deploy my JPA2 application on JBoss 5.1?

      Going to JBoss 6 is not an option since it is not GA yet.


      I can deploy my app in jetty/tomcat but not in JBoss... Never thought JBoss will be so rigid


      Thanks in advance for your help.

        • 1. Re: JBoss 5.1 GA + JPA 2
          Rajan Desai Newbie

          I tried deploying this application in JBoss 6.0 CR1, but was not successful... I get the following error:

          14:52:53,402 INFO  [AprLifecycleListener] The Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /Usr/local/jboss-6.0.0.CR1/bin/native/lib64
          14:52:53,548 INFO  [TomcatDeployment] deploy, ctxPath=/invoker
          14:52:53,962 INFO  [ModClusterService] Initializing mod_cluster 1.1.0.Final
          14:52:54,015 INFO  [RARDeployment] Required license terms exist, view vfs:/usr/local/jboss-6.0.0.CR1/server/default/deploy/jboss-local-jdbc.rar/META-INF/ra.xml
          14:52:54,030 INFO  [RARDeployment] Required license terms exist, view vfs:/usr/local/jboss-6.0.0.CR1/server/default/deploy/jboss-xa-jdbc.rar/META-INF/ra.xml
          14:52:54,063 INFO  [RARDeployment] Required license terms exist, view vfs:/usr/local/jboss-6.0.0.CR1/server/default/deploy/jms-ra.rar/META-INF/ra.xml
          14:52:54,082 WARN  [ClassLoaderManager] Unexpected error during load of:org.hornetq.api.core.client.ClientSession: java.lang.LinkageError: loader constraint violation: loader (instance of <bootloader>) previously initiated loading for a different type with name "javax/transaction/xa/XAResource"
              at java.lang.ClassLoader.findBootstrapClass(Native Method) [:1.6.0_22]
              at java.lang.ClassLoader.findBootstrapClassOrNull(ClassLoader.java:927) [:1.6.0_22]
              at java.lang.ClassLoader.loadClass(ClassLoader.java:298) [:1.6.0_22]
              at java.lang.ClassLoader.loadClass(ClassLoader.java:296) [:1.6.0_22]
              at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) [:1.6.0_22]
              at java.lang.ClassLoader.loadClass(ClassLoader.java:296) [:1.6.0_22]
              at java.lang.ClassLoader.loadClass(ClassLoader.java:248) [:1.6.0_22]
              at java.lang.Class.forName0(Native Method) [:1.6.0_22]
              at java.lang.Class.forName(Class.java:247) [:1.6.0_22]
              at org.jboss.classloader.plugins.loader.ClassLoaderToLoaderAdapter.loadClass(ClassLoaderToLoaderAdapter.java:184) [jboss-classloader.jar:2.2.0.Alpha9]
              at org.jboss.classloader.spi.ClassLoaderDomain.loadClassFromParent(ClassLoaderDomain.java:607) [jboss-classloader.jar:2.2.0.Alpha9]
              at org.jboss.classloader.spi.ClassLoaderDomain.loadClassBefore(ClassLoaderDomain.java:562) [jboss-classloader.jar:2.2.0.Alpha9]
              at org.jboss.classloader.spi.base.BaseClassLoaderDomain.loadClass(BaseClassLoaderDomain.java:249) [jboss-classloader.jar:2.2.0.Alpha9]


          I also see this:

          14:52:54,097 ERROR [AbstractKernelController] Error installing to Start: name=jboss.jca:name='jms-ra.rar',service=RARDeployment state=Create mode=Manual requiredState=Installed: org.jboss.deployers.spi.DeploymentException: Error for resource adapter class org.hornetq.ra.HornetQResourceAdapter accessing property setter ConfigPropertyMetaData@5eab5809[name=ConnectionParameters type=java.lang.String value=server-id=0 descriptions=[DescriptionMetaData@245f8da1[language=en description=The transport configuration. These values must be in the form of key=val;key=val;]]]
              at org.jboss.deployers.spi.DeploymentException.rethrowAsDeploymentException(DeploymentException.java:49) [:2.2.0.Alpha8]
              at org.jboss.resource.deployment.ResourceAdapterFactory.applyProperty(ResourceAdapterFactory.java:116) [:]
              at org.jboss.resource.deployment.ResourceAdapterFactory.createResourceAdapter(ResourceAdapterFactory.java:96) [:]
              at org.jboss.resource.deployment.ResourceAdapterFactory.createResourceAdapter(ResourceAdapterFactory.java:60) [:]


          I am using Mac OSX 10.6 and Java 1.6



          • 2. Re: JBoss 5.1 GA + JPA 2
            Jaikiran Pai Master

            Are you packaging any jar file(s) containing javax.transaction.* in your application packaging? If yes, then remove those jars from the application packaging.

            1 of 1 people found this helpful
            • 3. Re: JBoss 5.1 GA + JPA 2
              Rajan Desai Newbie

              Yes, taking out jta1.1.jar from my war file removed the exceptions listed above (JBoss 6.0 deployment). But now I see the following errors:


              09:49:32,062 ERROR [AbstractKernelController] Error installing to Start: name=persistence.unit:unitName=gateway-2.2.4-SNAPSHOT.war#ApplicationEntityManager state=Create: java.lang.RuntimeException: Specification violation [EJB3 JPA] - You have not defined a non-jta-data-source for a RESOURCE_LOCAL enabled persistence context named: ApplicationEntityManager
                  at org.jboss.jpa.impl.deployment.PersistenceUnitInfoImpl.<init>(PersistenceUnitInfoImpl.java:133) [:2.0.0]


              The current war file works fine in Jetty or Tomcat. Is <non-jata-data-source> a mandatory element in persistence.xml... I didn't think so.


              Does any one have ideas to get JPA 2 application working on JBoss 5.1?



              • 4. Re: JBoss 5.1 GA + JPA 2 (Resolved ?)
                Rajan Desai Newbie

                I managed to deploy my JPA 2 application on JBoss 51 successfully. I can successfuly deploy and access DB after making the following changes.

                (Please let me know if you see any issues with this solution)


                1. Add support for persistence 2 schema
                  • copy persistence_2_0.xsd to <JBOSS_51_INSTALL_DIR>/docs/schema directory
                  • Modify  <JBOSS_51_INSTALL_DIR>/server/default/deployers/metadata-deployer-jboss-beans.xml  to add the following lines after persistence_1_0.xsd entry:

                2. Once JBoss 51 installation is enabled for JPA 2, the following changes are needed in the JPA 2 project.
                  • Add jboss-classloading.xml file in src/main/webapp/WEB-INF directory. Add the following lines to this file.
                    <?xml version="1.0" encoding="UTF-8"?>
                    <classloading xmlns="urn:jboss:classloading:1.0"

                    The above change ensures that the classes from your WEB-INF/LIB directory are loaded before the classes that come with JBoss. Ensure that all JPA 2 and Hibernate related jar files are included/packaged with your application (war/ear). Here is the list of jars included in my application
                    • WEB-INF/lib/hibernate-annotations-3.5.1-Final.jar 
                    • WEB-INF/lib/hibernate-c3p0-3.5.1-Final.jar
                    • WEB-INF/lib/hibernate-commons-annotations-3.2.0.Final.jar
                    • WEB-INF/lib/hibernate-core-3.5.1-Final.jar
                    • WEB-INF/lib/hibernate-entitymanager-3.5.1-Final.jar
                    • WEB-INF/lib/hibernate-jpa-2.0-api-1.0.0.Final.jar
                    • WEB-INF/lib/hibernate-validator-4.0.2.GA.jar
                    • WEB-INF/lib/slf4j-api-1.5.6.jar
                    • WEB-INF/lib/slf4j-log4j12-1.5.6.jar
                    • WEB-INF/lib/spring-aop-3.0.4.RELEASE.jar
                    • WEB-INF/lib/spring-asm-3.0.4.RELEASE.jar
                    • WEB-INF/lib/spring-beans-3.0.4.RELEASE.jar
                    • WEB-INF/lib/spring-context-3.0.4.RELEASE.jar
                    • WEB-INF/lib/spring-context-support-3.0.4.RELEASE.jar
                    • WEB-INF/lib/spring-core-3.0.4.RELEASE.jar
                    • WEB-INF/lib/spring-expression-3.0.4.RELEASE.jar
                    • WEB-INF/lib/spring-jdbc-3.0.4.RELEASE.jar
                    • WEB-INF/lib/spring-orm-3.0.4.RELEASE.jar
                    • WEB-INF/lib/spring-oxm-3.0.4.RELEASE.jar
                    • WEB-INF/lib/spring-tx-3.0.4.RELEASE.jar
                    • WEB-INF/lib/spring-web-3.0.4.RELEASE.jar
                    • WEB-INF/lib/spring-webmvc-3.0.4.RELEASE.jar
                    • WEB-INF/lib/stax-api-1.0-2.jar
                    • WEB-INF/lib/validation-api-1.0.0.GA.jar

                • 5. Re: JBoss 5.1 GA + JPA 2
                  Sam Tsang Newbie

                  Thank you Rajan. I will try your method very soon and let everyone know the result. I have been struggling to deploy JPA 2 (with EJB 2.1) on JBoss for a couple of weeks but always failed. I used JBoss 6.0 CR1 but am hoping to use the final version as soon as possible. Why don't you try JBoss 6 as the GA will be available this month IMHO ?.

                  • 6. JBoss 5.1 GA + JPA 2
                    Jose Ferrer Newbie

                    I did something like this but it doesn't quite seem to work.  Just in case it makes a difference, I'm deploying a WAR to EAP 5.0.1 and I can't switch to JBoss 6.0.


                    With the jboss-classloading.xml file exactly as yours, everything appears to work.  However the Hibernate version in the log is 3.3 and if I try to use EntityManager.detach() (new for JPA 2) I get a method not found exception at runtime.  This leads me to believe that the EntityManagerFactory I get from calling Persistence.createEntityManagerFactory() is getting created by the Hibernate 3.3 that is in JBoss, not the one in the WAR file.  If I add a domain="SomeOtherDomain" setting to the classloading tag (I don't remember where I got the idea) I get class cast exceptions from org.hibernate.ejb.HibernatePersistence to javax.persistence.spi.PersistenceProvider.  I think that's because it is trying to cast across classloaders.  However, if I create my own Ejb3Configuration and get an EntityManagerFactory through it, then I see in the log output that Hibernate 3.5.1 is being used and EntityManager.detach() works just fine.

                    • 7. Re: JBoss 5.1 GA + JPA 2 (Resolved ?)
                      d2004 Newbie

                      Hi Rajan,

                      I followed the steps you mentioned but I am getting the following error

                      14:15:05,461 ERROR [[requestFactoryServlet]] Servlet.service() for servlet requestFactoryServlet threw exception

                      javax.persistence.PersistenceException: Invalid persistence.xml.

                      Error parsing XML (line-1 : column -1): cvc-complex-type.4: Attribute 'version' must appear on element 'persistence'.


                              at org.hibernate.ejb.packaging.PersistenceXmlLoader.loadURL(PersistenceXmlLoader.java:145)

                      • 8. Re: JBoss 5.1 GA + JPA 2 (Resolved ?)
                        Yasser Marie Newbie


                        If you are still having this issue, I managed to solve a similar one by following instructions from here: http://java.dzone.com/articles/ejb3-jpa-error-when-migrating




                        • 9. Re: JBoss 5.1 GA + JPA 2
                          stephan972 Newbie

                          I have build a workaround for solving this problem.

                          I explain it here : http://stackoverflow.com/q/8476944/363573