0 Replies Latest reply on Jan 27, 2011 8:22 PM by infinity2heaven

    Could not resolve a persistence unit corresponding to the persistence-context-ref-name

    infinity2heaven

      I installed a modified version of the standard weld archetype with hibernate as a persistence provider. The war installs just fine on JBoss 6 but doesn't install on Glassfish. Here's the error,



      com.sun.enterprise.admin.cli.CommandException: remote failure: Exception while preparing the app : java.lang.RuntimeException: Could not resolve a persistence unit corresponding to the persistence-context-ref-name [xxx.MemberRepositoryProducer/em] in the scope of the module called [admin.app]. Please verify your application.
      




      I tried adding a

      name="primary"

      in the injected PersistenceContext in xxx.MemberRepositoryProducer. Still get the error:



      com.sun.enterprise.admin.cli.CommandException: remote failure: Exception while preparing the app : java.lang.RuntimeException: Could not resolve a persistence unit corresponding to the persistence-context-ref-name [primary] in the scope of the module called [admin.app]. Please verify your application.
      





      Here's the persistence unit.





      <?xml version="1.0" encoding="UTF-8"?>
      <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="primary">
                      
                      <provider>org.hibernate.ejb.HibernatePersistence</provider>
                      
                      <!-- jdbc/__default is the default data source in GlassFish -->
                      <jta-data-source>jdbc/admin_app</jta-data-source>
                      <properties>
                              
                              <property name="hibernate.ejb.naming_strategy" value="com.xxx.NamingStrategy"/>
                              <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
                              <property name="hibernate.hbm2ddl.auto" value="create"/>
                  
                              <!-- Properties for EclipseLink (default provider for GlassFish) -->
                              <!--
                              <property name="eclipselink.ddl-generation" value="drop-and-create-tables"/>
                              <property name="eclipselink.logging.level" value="FINE"/>
                              -->
      
                              <!-- Cache properties -->
                              <property name="hibernate.cache.use_second_level_cache" value="true"/>
                              <property name="hibernate.cache.provider_class" value="net.sf.ehcache.hibernate.EhCacheProvider"/>
                              <property name="hibernate.cache.use_query_cache" value="true"/> 
                              
                              <!-- Logging properties -->
                              <property name="hibernate.show_sql" value="true" />
                              <property name="hibernate.format_sql" value="true" />
                              <property name="hibernate.generate_statistics" value="false" />
                              <property name="hibernate.use_sql_comments" value="true" />
      
                              <!-- Auditing properties -->
                              <property name="hibernate.ejb.event.post-insert" value="org.hibernate.envers.event.AuditEventListener"/>
                              <property name="hibernate.ejb.event.post-update" value="org.hibernate.envers.event.AuditEventListener"/>
                              <property name="hibernate.ejb.event.post-delete" value="org.hibernate.envers.event.AuditEventListener"/>
                              <property name="hibernate.ejb.event.pre-collection-update" value="org.hibernate.envers.event.AuditEventListener"/>
                              <property name="hibernate.ejb.event.pre-collection-remove" value="org.hibernate.envers.event.AuditEventListener"/>
                              <property name="hibernate.ejb.event.post-collection-recreate" value="org.hibernate.envers.event.AuditEventListener"/>
                              <property name="org.hibernate.envers.auditTableSuffix" value="_audit"/>
                              
                      </properties>
              </persistence-unit>
      </persistence>



      The only other jars in the war is weld.extensions.1.0.0.Beta1 in the WEB-INF/lib. The original weld archetype had Alpha-2 version which I tried too.


      I read this blog and added the persistence-context-ref in my web.xml





      <persistence-context-ref>
          <persistence-context-ref-name>main</persistence-context-ref-name>
          <persistence-unit-name>primary</persistence-unit-name>
      </persistence-context-ref>
      



      and then referred to the injected PersistenceContext as name="main"


      Still the same issue.


      Thoughts?