title: Persistance in JBoss wildfly (in a spring application)
body: <p>I have a spring 3.2 application which has defined persisence with the following configuration:</p>
  
  <pre><code>&lt;bean id="jpaVendorAdapter" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"&gt;
      &lt;property name="database" value="MYSQL"/&gt;
      &lt;property name="showSql" value="false"/&gt;
      &lt;property name="generateDdl" value="false"/&gt;
      &lt;property name="databasePlatform" value="org.hibernate.dialect.MySQL5Dialect"/&gt;
  &lt;/bean&gt;
  
  &lt;util:map id="jpaPropertyMap"&gt;
          &lt;entry key="hibernate.hbm2ddl.auto" value="update"/&gt;
          &lt;entry key="hibernate.cache.use_query_cache" value="true" /&gt;
          &lt;entry key="hibernate.max_fetch_depth" value="4" /&gt;
          &lt;entry key="hibernate.show_sql" value="false" /&gt;
          &lt;entry key="hibernate.format_sql" value="false" /&gt;
          &lt;entry key="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.JBossAppServerJtaPlatform" /&gt;
          &lt;entry key="hibernate.transaction.factory_class" value="org.hibernate.engine.transaction.internal.jta.CMTTransactionFactory" /&gt;
          &lt;entry key="hibernate.connection.autocommit" value="false" /&gt;
  &lt;/util:map&gt;
  
  &lt;bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&gt;
          &lt;property name="jpaVendorAdapter" ref="jpaVendorAdapter"/&gt;      
          &lt;property name="jtaDataSource" ref="dataSource"  /&gt;
          &lt;property name="jpaPropertyMap" ref="jpaPropertyMap" /&gt;
          &lt;property name="persistenceUnitManager" ref="persistenceUnitManager" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="persistenceUnitManager" class="org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager" &gt;
          &lt;property name="packagesToScan"  value="gr.hcg.nautologhsh.domain" /&gt;
          &lt;property name="defaultJtaDataSource" ref="dataSource" /&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>My entity classes exist under the gr.hcg.nautologhsh.domain package. I am not using any <code>persistance.xml</code> files.</p>
  
  <p>Now, this configuration is working fine in JBoss 8 wildfly. However when I see the Administration console of JBoss, in the tag JPA, I don't see any persistance units. </p>
  
  <p>From some googling I think that the persistence units have to be configured through JBoss and not through Spring in order to be visible there - is that true ? I can't really understand why there could be different PUs in JBoss - how can they be used ? The documentation of JBoss is very spartian in that subject and I couldn't understand many things :(</p>
  
  <p>Can somebody explain to me how can I define JBoss persistence units and show these in the JPA tag of wildfly's administration console ?</p>
  
  <p><strong>Update</strong></p>
  
  <p>I created a persistence.xml with the following contents:</p>
  
  <pre><code>&lt;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_2_0.xsd"
               version="2.0"&gt;
  
      &lt;persistence-unit name="nautologhshPU" transaction-type="JTA"&gt;
  
          &lt;jta-data-source&gt;java:jboss/datasources/nautologhsh&lt;/jta-data-source&gt;
  
      &lt;/persistence-unit&gt;
  &lt;/persistence&gt;
  </code></pre>
  
  <p>changed my <code>datasource-config.xml</code> beans like ths:</p>
  
  <pre><code>&lt;jee:jndi-lookup  id="dataSource" jndi-name="java:jboss/datasources/nautologhsh" resource-ref="false" /&gt;
  
  &lt;tx:jta-transaction-manager  /&gt;
  
  &lt;jee:jndi-lookup jndi-name="java:comp/env/jpa/EntityManager" id="entityManager" expected-type="javax.persistence.EntityManager" /&gt;
  </code></pre>
  
  <p>and added the following to <code>web.xml</code></p>
  
  <pre><code>&lt;persistence-context-ref&gt;
      &lt;persistence-context-ref-name&gt;jpa/EntityManager&lt;/persistence-context-ref-name&gt;
      &lt;persistence-unit-name&gt;nautologhshPU&lt;/persistence-unit-name&gt;
  &lt;/persistence-context-ref&gt;
  </code></pre>
  
  <p>And now get the following error:</p>
  
  <pre><code>20:24:41,839 ERROR [org.jboss.msc.service.fail] (ServerService Thread Pool -- 52) MSC000001: Failed to start service jboss.persistenceunit."Nautologhsh.war#nautologhshPU": org.jboss.msc.service.StartException in service jboss.persistenceunit."Nautologhsh.war#nautologhshPU": org.hibernate.service.UnknownServiceException: Unknown service requested [org.hibernate.service.classloading.spi.ClassLoaderService]
          at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:169) [wildfly-jpa-8.0.0.Beta1.jar:8.0.0.Beta1]
          at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:117) [wildfly-jpa-8.0.0.Beta1.jar:8.0.0.Beta1]
          at java.security.AccessController.doPrivileged(Native Method) [rt.jar:1.7.0_45]
          at org.wildfly.security.manager.WildFlySecurityManager.doChecked(WildFlySecurityManager.java:463) [wildfly-security-manager-1.0.0.Beta3.jar:1.0.0.Beta3]
          at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1.run(PersistenceUnitServiceImpl.java:178) [wildfly-jpa-8.0.0.Beta1.jar:8.0.0.Beta1]
          at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_45]
          at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_45]
          at java.lang.Thread.run(Thread.java:744) [rt.jar:1.7.0_45]
          at org.jboss.threads.JBossThread.run(JBossThread.java:122) [jboss-threads-2.1.1.Final.jar:2.1.1.Final]
  Caused by: org.hibernate.service.UnknownServiceException: Unknown service requested [org.hibernate.service.classloading.spi.ClassLoaderService]
          at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:127)
          at org.hibernate.envers.event.EnversIntegrator.integrate(EnversIntegrator.java:65)
          at org.hibernate.internal.SessionFactoryImpl.&lt;init&gt;(SessionFactoryImpl.java:310)
          at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1837)
          at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:854)
          at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:847)
          at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:396)
          at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:846)
          at org.jboss.as.jpa.hibernate4.TwoPhaseBootstrapImpl.build(TwoPhaseBootstrapImpl.java:44)
          at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:151) [wildfly-jpa-8.0.0.Beta1.jar:8.0.0.Beta1]
          ... 8 more
  
  20:24:41,861 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) JBAS014613: Operation ("deploy") failed - address: ([("deployment" =&gt; "Nautologhsh.war")]) - failure description: {"JBAS014671: Failed services" =&gt; {"jboss.persistenceunit.\"Nautologhsh.war#nautologhshPU\"" =&gt; "org.jboss.msc.service.StartException in service jboss.persistenceunit.\"Nautologhsh.war#nautologhshPU\": org.hibernate.service.UnknownServiceException: Unknown service requested [org.hibernate.service.classloading.spi.ClassLoaderService]
      Caused by: org.hibernate.service.UnknownServiceException: Unknown service requested [org.hibernate.service.classloading.spi.ClassLoaderService]"}}
  </code></pre>
  
  <p>Does any body know what is this <code>org.hibernate.service.UnknownServiceException: Unknown service requested [org.hibernate.service.classloading.spi.ClassLoaderService]</code> ??</p>