11 Replies Latest reply on Apr 25, 2013 6:16 AM by nickarls

    Application Managed EntityManager JBoss AS 7

    mbuamuh

      Hi,

       

      i am using an application managed Entity manager and get it using the following code:

       

      private static String persistenceUnitName="eccore-ejb";

       

      private EntityManager getEntityManager() {

      EntityManagerFactory entityManagerFactory = Persistence .createEntityManagerFactory(persistenceUnitName);

      EntityManager entityManager = entityManagerFactory .createEntityManager();

      return entityManager;

      }

       

       


      But i keep getting an exception that there is no persistent provider. However my server logs show that the default persistence provider org.hibernate.ejb.HibernatePersistence is being used for that Persistence Unit. Following is my persistence.xml content and the error message. Does anyone have an idea what i might be doing wrong or come across this and how did they solve it?

       

       

       

      persistence:persistence version="2.0" xmlns:persistence="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:persistence-unit name="eccore-ejb" transaction-type="JTA"

       

       

      >

       

       

       

      <persistence:provider>org.hibernate.ejb.HibernatePersistence</persistence:provider

       

       

      >

       

       

       

      <persistence:jta-data-source>java:jboss/datasources/ECPM_DEV</persistence:jta-data-source

       

       

      >

       

       

       

      <persistence:jar-file>com.ec.eccore-ejb-0.0.1-SNAPSHOT</persistence:jar-file

       

       

      >

       

       

       

      <persistence:class>com.ec.eccore.util.resourcebundle.model.entities.BasisLanguageEntity</persistence:class

       

       

      >

       

       

       

      <persistence:class>com.ec.eccore.util.resourcebundle.model.entities.LanguageSourceEntity</persistence:class

       

       

      >

       

       

       

      <persistence:class>com.ec.eccore.util.resourcebundle.model.entities.LanguageTargetEntity</persistence:class

       

       

      >

       

       

       

      <persistence:shared-cache-mode>ENABLE_SELECTIVE</persistence:shared-cache-mode

       

       

      >

       

       

       

      <persistence:properties

       

       

      >

       

       

       

      <persistence:property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect"

       

       

      />

       

       

       

      <persistence:property name="hibernate.show_sql" value="true"

       

       

      />

       

       

       

      <persistence:property name="hibernate.cache.provider_class" value="org.hibernate.cache.SingletonEhCacheProvider"

       

       

      />

       

       

       

      <persistence:property name="hibernate.cache.use_second_level_cache" value="true"

       

       

      />

       

       

       

      <persistence:property name="hibernate.cache.use_query_cache" value="true"

       

       

      />

       

       

       

       

       

       

      <!-- The region factory property is the "new" property (for Hibernate

      3.3 and above) -->

       

       

       

       

       

       

      <!--property name="hibernate.cache.region.factory_class" value="net.sf.ehcache.hibernate.EhCacheRegionFactory"/ -->

       

       

       

      </persistence:properties

       

       

      >

       

       

       

      </persistence:persistence-unit

       

       

      >

      </

       

       

       

      persistence:persistence

      >

       

       

       

       

      Caused by:

      javax.persistence.PersistenceException

      : No Persistence provider for EntityManager named eccore-ejb

      at javax.persistence.Persistence.createEntityManagerFactory(

       

      Persistence.java:69

      ) [hibernate-jpa-2.0-api-1.0.1.Final.jar:1.0.1.Final]

      at javax.persistence.Persistence.createEntityManagerFactory(

       

      Persistence.java:47

      ) [hibernate-jpa-2.0-api-1.0.1.Final.jar:1.0.1.Final]

      at com.ec.eccore.util.security.ObjectAccessInfoVer3.getEntityManager(

       

      ObjectAccessInfoVer3.java:78

      ) [com.ec.eccore-ejb-0.0.1-SNAPSHOT.jar:]

       

       

       

       

       

       

        • 1. Re: Application Managed EntityManager JBoss AS 7.1.1
          smarlow

          Yes, the Hibernate module hasn't been loaded yet.  Try to recreate with the EAP alpha built from AS7.

          • 2. Re: Application Managed EntityManager JBoss AS 7.1.1
            smarlow

            Also, this forum is strictly for discussing EAP.  Since you are going to switch to the EAP alpha that I just told you about, your fine to stay here. 

             

            If you don't switch EAP for some reason, you can use the https://community.jboss.org/en/jbossas7 forum to ask questions.

            • 3. Re: Application Managed EntityManager JBoss AS 7.1.1
              mbuamuh

              Hi Scott, i have moved to EAP 6.1 Alpha, and is having the same Exception as above mentioned. Could the following be the reason? Or am i missing something? The weird thing is the persistence.xml file is read.

               

              The error happens in org.hibernate.ejb.packaging.PersistenceXmlLoader.depoly(...) For some reason the whole persistence.xml file is not read. Just the top of it is read. Any headway on this???

               

              public static List<PersistenceMetadata> deploy(URL url, Map overrides, EntityResolver resolver,

                                                                 PersistenceUnitTransactionType defaultTransactionType) throws Exception {

                      Document doc = loadURL( url, resolver );

                      Element top = doc.getDocumentElement();

                      //version is mandatory

                      final String version = top.getAttribute( "version" );

               

                      NodeList children = top.getChildNodes();

                      ArrayList<PersistenceMetadata> units = new ArrayList<PersistenceMetadata>();

                      for ( int i = 0; i < children.getLength() ; i++ ) {

                          if ( children.item( i ).getNodeType() == Node.ELEMENT_NODE ) {

                              Element element = (Element) children.item( i );

                              String tag = element.getTagName();

                              if ( tag.equals( "persistence-unit" ) ) {

                                  PersistenceMetadata metadata = parsePersistenceUnit( element );

                                  metadata.setVersion(version);

                                  //override properties of metadata if needed

                                  if ( overrides.containsKey( AvailableSettings.PROVIDER ) ) {

                                      String provider = (String) overrides.get( AvailableSettings.PROVIDER );

                                      metadata.setProvider( provider );

                                  }

                                  if ( overrides.containsKey( AvailableSettings.TRANSACTION_TYPE ) ) {

                                      String transactionType = (String) overrides.get( AvailableSettings.TRANSACTION_TYPE );

                                      metadata.setTransactionType( PersistenceXmlLoader.getTransactionType( transactionType ) );

                                  }

                                  if ( overrides.containsKey( AvailableSettings.JTA_DATASOURCE ) ) {

                                      String dataSource = (String) overrides.get( AvailableSettings.JTA_DATASOURCE );

                                      metadata.setJtaDatasource( dataSource );

                                  }

                                  if ( overrides.containsKey( AvailableSettings.NON_JTA_DATASOURCE ) ) {

                                      String dataSource = (String) overrides.get( AvailableSettings.NON_JTA_DATASOURCE );

                                      metadata.setNonJtaDatasource( dataSource );

                                  }

                                  /*

                                   * if explicit => use it

                                   * if JTA DS => JTA transaction

                                   * if non JTA DA => RESOURCE_LOCAL transaction

                                   * else default JavaSE => RESOURCE_LOCAL

                                   */

                                  PersistenceUnitTransactionType transactionType = metadata.getTransactionType();

                                  Boolean isJTA = null;

                                  if ( StringHelper.isNotEmpty( metadata.getJtaDatasource() ) ) {

                                      isJTA = Boolean.TRUE;

                                  }

                                  else if ( StringHelper.isNotEmpty( metadata.getNonJtaDatasource() ) ) {

                                      isJTA = Boolean.FALSE;

                                  }

                                  if (transactionType == null) {

                                      if (isJTA == Boolean.TRUE) {

                                          transactionType = PersistenceUnitTransactionType.JTA;

                                      }

                                      else if (isJTA == Boolean.FALSE) {

                                          transactionType = PersistenceUnitTransactionType.RESOURCE_LOCAL;

                                      }

                                      else {

                                          transactionType = defaultTransactionType;

                                      }

                                  }

                                  metadata.setTransactionType( transactionType );

                                  Properties properties = metadata.getProps();

                                  ConfigurationHelper.overrideProperties( properties, overrides );

                                  units.add( metadata );

                              }

                          }

                      }

                      return units;

                  }

              • 4. Re: Application Managed EntityManager JBoss AS 7.1.1
                smarlow

                Maybe invalid syntax in the persistence.xml?

                • 5. Re: Application Managed EntityManager JBoss AS 7.1.1
                  mbuamuh

                  My persistence.xml file looks like this; and it works find for container managed entity manager.

                  <?xml version="1.0" encoding="UTF-8"?>

                  <persistence:persistence version="2.0" xmlns:persistence="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:persistence-unit name="eccore-ejb" transaction-type="JTA">

                     <persistence:provider>org.hibernate.ejb.HibernatePersistence</persistence:provider>

                     <persistence:jta-data-source>java:jboss/datasources/ECPM_DEV</persistence:jta-data-source>

                     <persistence:jar-file>com.ec.eccore-ejb-0.0.1-SNAPSHOT</persistence:jar-file>

                     <persistence:class>com.ec.eccore.util.resourcebundle.model.entities.BasisLanguageEntity</persistence:class>

                     <persistence:class>com.ec.eccore.util.resourcebundle.model.entities.LanguageSourceEntity</persistence:class>

                     <persistence:class>com.ec.eccore.util.resourcebundle.model.entities.LanguageTargetEntity</persistence:class>

                     <persistence:shared-cache-mode>ENABLE_SELECTIVE</persistence:shared-cache-mode>

                     <persistence:properties>

                    <persistence:property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect"/>

                    <persistence:property name="hibernate.show_sql" value="true"/>

                    <persistence:property name="hibernate.cache.provider_class" value="org.hibernate.cache.SingletonEhCacheProvider"/>

                    <persistence:property name="hibernate.cache.use_second_level_cache" value="true"/>

                    <persistence:property name="hibernate.cache.use_query_cache" value="true"/>

                   

                    <!-- The region factory property is the "new" property (for Hibernate

                                  3.3 and above) -->

                              <!--property name="hibernate.cache.region.factory_class" value="net.sf.ehcache.hibernate.EhCacheRegionFactory"/ -->

                     </persistence:properties>

                    </persistence:persistence-unit>

                  </persistence:persistence>

                  • 6. Re: Application Managed EntityManager JBoss AS 7.1.1
                    smarlow

                    The Hibernate parser (for persistence.xml) may be more sensitive to syntax errors than the container managed (org.jboss.as.jpa subsystem) parser.

                     

                    Before deploying your application, try deploying the attached 2lc.jar to ensure that the Hibernate provider is loaded (so that 2lc.jar is deployed while your also deploying your app).

                     

                    Contents of 2lc.jar is pretty minimal (container managed persistence unit + an entity):

                    META-INF/

                    META-INF/MANIFEST.MF

                    Employee.class

                    Employee.java

                    META-INF/persistence.xml

                     

                    Also, attach your as/standalone/log/server.log after attempting to deploy your app.

                    • 7. Re: Application Managed EntityManager JBoss AS 7.1.1
                      mbuamuh

                      Hi Scott, i have deployed them as requested. The server log file is attached to the original message. I couldn't attach it to this message thats why i put it there. Please let me know if you find out something.

                      • 8. Re: Application Managed EntityManager JBoss AS 7.1.1
                        nickarls

                        Just for fun, have you tried with the default namespace in persistence.xml?

                        • 9. Re: Application Managed EntityManager JBoss AS 7.1.1
                          smarlow

                          It could be something like that.  Might also enable org.hibernate trace logging and examine the output.

                           

                          From looking at the server.log attached to the first message, I see that we are successfully starting the EE (JPA) container side eccore-ejb persistence unit.  Another option could be to use that (via @PersistenceContext EntityManager) instead of bootstrapping via the Persistence api.

                          • 10. Re: Application Managed EntityManager JBoss AS 7.1.1
                            mbuamuh

                            It worked with the default Namespace in the perisitence.xml. Thanks for the tip.

                            • 11. Re: Application Managed EntityManager JBoss AS 7.1.1
                              nickarls

                              Whoa, long shot! ;-) Perhaps Scott can comment on if this is a bug or a side-effect of something?