9 Replies Latest reply: May 31, 2012 1:48 AM by Rafael Jesus RSS

No persistence provider for EntityManager named scrum

Rafael Jesus Newbie

Hey all,

 

After 2 weeks configuring my Java app with maven + jboss as 7, i can´t run my simple junit tests, here goes my code and how im configuring my persistence.xml:

 

PS: My Web app is ok, just tests is not working

 

public class TestUsuarioRepository {
  
          private static EntityManager em; 
          private static UsuarioDao usuarioDao;


          @BeforeClass 
          public static void before() throws Exception {
                    em = new JPAUtil().getEntityManager();
                    usuarioDao = new UsuarioDaoImpl();
          }

          @AfterClass
          public static void after() throws Exception { 
                    em.close();
          }

          @Test     
         private void salvaNovoUsuario() throws Exception 
                    final Usuario u = new Usuario(); 
                    u.setNome("Rafael");
                    u.setLogin("adm");
                    u.setSenha("123");
                    u.setRole(UsuarioRole.TEAM);
                    usuarioDao.salva(u);
                    assertNotNull(u.getId());                     
          }
  }

 

 

public class JPAUtil {

          private static EntityManagerFactory factory = Persistence.createEntityManagerFactory(Const.SCHEMA);

          @Produces 
          @RequestScoped
          public EntityManager getEntityManager() {
                    return factory.createEntityManager();
          }

          public void close(@Disposes EntityManager em) {
                    em.close();
          }
}

 

Here if i don´t map my entities, when i run my web app, it does not find my mapped classes, so Why?

<persistence-unit name="scrum" transaction-type="RESOURCE_LOCAL">
                    <provider>org.hibernate.ejb.HibernatePersistence</provider>
                    <non-jta-data-source>java:jboss/postgresDS</non-jta-data-source> 
                    <class>br.com.scrum.domain.entity.Usuario</class>
                    <class>br.com.scrum.domain.entity.Projeto</class>
                    <class>br.com.scrum.domain.entity.Sprint</class>
                    <class>br.com.scrum.domain.entity.Item</class>
                    <class>br.com.scrum.domain.entity.Tarefa</class>
                    <properties> 
                              <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" />
                              <property name="hibernate.connection.driver_class" value="org.postgresql.Driver" />
                              <property name="hibernate.connection.username" value="postgres" />
                              <property name="hibernate.connection.password" value="rafa1986" />
                              <property name="hibernate.connection.url" value="jdbc:postgresql:postgres:5432/postgres" /> 
                              <property name="hibernate.hbm2ddl.auto" value="update" />
                              <property name="hibernate.show_sql" value="true" />
                              <property name="hibernate.format_sql" value="true" />
                              <property name="hibernate.c3p0.min_size" value="5" />
                              <property name="hibernate.c3p0.max_size" value="20" />
                              <property name="hibernate.c3p0.timeout" value="180" />
                              <property name="hibernate.c3p0.idle_test_period" value="100" />
                    </properties>
          </persistence-unit>

  • 1. Re: No persistence provider for EntityManager named scrum
    Rafael Jesus Newbie

    I forgot to tell ya, when i run my class that gererate tables on my database i got the same error??

     

    Please guys im really want to use as 7, in tomcat i just press the button and i have everthing ok..

     

    Here is my project on Github https://github.com/rafaeljesus

     

    Tks!!

  • 2. Re: No persistence provider for EntityManager named scrum
    Rafael Jesus Newbie

    I think its a pom depency problem, i use jboss pom  exemples on availables archetypes..

     

    Sure im missing something, any help will be welcome

     

    Tks

  • 3. Re: No persistence provider for EntityManager named scrum
    Scott Marlow Master

    Show us the full exception call stack here and the test errors here. 

  • 4. Re: No persistence provider for EntityManager named scrum
    Rafael Jesus Newbie

    Thanks for responding Scott, and sorry for the delay .. as requested follows the trace of the exception. I even thought the error was because of the libraries are as provided in the pom as you can see here https://github.com/rafaeljesus/agile2go/blob/master/pom.xml

     

    but that it is not..so I got very cofusing, here the problem:

     

    tks..

     


    java.lang.ExceptionInInitializerError

              at br.com.scrum.domain.repository.usuario.TestUsuarioRepository.before(TestUsuarioRepository.java:36)

              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

              at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

              at java.lang.reflect.Method.invoke(Method.java:597)

              at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)

              at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)

              at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)

              at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)

              at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)

              at org.junit.runners.ParentRunner.run(ParentRunner.java:236)

              at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)

              at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)

              at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)

              at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)

              at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)

              at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

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

              at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:914)

              at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:889)

              at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:56)

              at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:63)

              at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:47)

              at br.com.scrum.infrastructure.dao.JPAUtil.<clinit>(JPAUtil.java:14)

              ... 17 more

    Caused by: org.hibernate.service.jndi.JndiException: Error parsing JNDI name [java:jboss/postgresDS]

              at org.hibernate.service.jndi.internal.JndiServiceImpl.parseName(JndiServiceImpl.java:92)

              at org.hibernate.service.jndi.internal.JndiServiceImpl.locate(JndiServiceImpl.java:63)

              at org.hibernate.service.jdbc.connections.internal.DatasourceConnectionProviderImpl.configure(DatasourceConnectionProviderImpl.java:116)

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

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

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

              at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.buildJdbcConnectionAccess(JdbcServicesImpl.java:223)

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

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

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

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

              at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:71)

              at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2273)

              at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2269)

              at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1738)

              at org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:88)

              at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:904)

              ... 22 more

    Caused by: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial

              at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)

              at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)

              at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:325)

              at javax.naming.InitialContext.getNameParser(InitialContext.java:480)

              at org.hibernate.service.jndi.internal.JndiServiceImpl.parseName(JndiServiceImpl.java:86)

              ... 38 more

     

     

    java.lang.NullPointerException

              at br.com.scrum.domain.repository.usuario.TestUsuarioRepository.after(TestUsuarioRepository.java:45)

              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

              at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

              at java.lang.reflect.Method.invoke(Method.java:597)

              at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)

              at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)

              at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)

              at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:37)

              at org.junit.runners.ParentRunner.run(ParentRunner.java:236)

              at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)

              at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)

              at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)

              at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)

              at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)

              at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

     

     


  • 5. Re: No persistence provider for EntityManager named scrum
    Scott Marlow Master

    It looks like you have written a Hibernate application that can mostly run outside of the AS7 server, except your depending on the AS7 server to define the java:jboss/postgresDS datasource and probably other things. 

     

    I think that you should look at using Arquillian which addresses what your trying to accomplish.

     

    Take a look at http://www.jboss.org/arquillian.html and the doc here.

     

    Scott

  • 6. Re: No persistence provider for EntityManager named scrum
    Rafael Jesus Newbie

    Hi Scott,

     

    Tks for the answer, i did not know that i could test aquillian with junit tests..

     

    I´ll try later,

     

    Tks a lot,

     

    Cheers

  • 7. Re: No persistence provider for EntityManager named scrum
    jaikiran pai Master

    By the way, Arquillian just got a brand new site http://arquillian.org/ and (probably) more up-to-date guides here http://arquillian.org/guides/

  • 8. Re: No persistence provider for EntityManager named scrum
    Rafael Jesus Newbie

    Tks for the sugestion jaikiran,

     

    I can´t run Arquillian tests cuz im facing in the trouble below when I try to generate my tables with hibernate:

     

    Caused by: org.hibernate.service.jndi.JndiException: Error parsing JNDI name [java:jboss/postgresDS]

              at org.hibernate.service.jndi.internal.JndiServiceImpl.parseName(JndiServiceImpl.java:92)

              at org.hibernate.service.jndi.internal.JndiServiceImpl.locate(JndiServiceImpl.java:63)

              at org.hibernate.service.jdbc.connections.internal.DatasourceConnectionProviderImpl.configure(DatasourceConnectionProviderImpl.java:116)

    ......more

    Caused by: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial

              at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)

     

    Just to make it simple here is my persistence.xml => https://github.com/rafaeljesus/agile2go/blob/master/src/main/resources/META-INF/persistence.xml

     

    My pom.xml => https://github.com/rafaeljesus/agile2go/blob/master/pom.xml

     

    My CreateTables =>https://github.com/rafaeljesus/agile2go/blob/master/src/main/java/br/com/scrum/infrastructure/dao/CreateTables.java

     

    Any help will be welcome guys..

     

    Tks,

     

    Rafael Jesus

  • 9. Re: No persistence provider for EntityManager named scrum
    Rafael Jesus Newbie

    Just to answer All I´d did to run tests, create tables, etc... was to comment in my persistence the the tag <jta-data-source>java:jboss/postgresDS</jta-data-source>

     

    Tks for all