[jboss-user] [JBoss Seam] - PersistenceException during testNG unit test

asookazian do-not-reply at jboss.com
Wed Jan 24 14:54:06 EST 2007


Based on the following persistence.xml file (which is located in my Eclipse project's resources/META-INF folder):

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

	<persistence-unit name="RSDB">		org.hibernate.ejb.HibernatePersistence
		<jta-data-source>java:jdbc/RespaJbossDS</jta-data-source>
		
			
			
			<!-- These are the default for JBoss EJB3, but not for HEM: -->
			
			
		
	</persistence-unit>



I get the following excpetion in the testNG plugin window in Eclipse when I run my testNG test suite:

javax.persistence.PersistenceException: No Persistence provider for EntityManager named RSDB
	at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:41)
	at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:27)
	at example1.DashboardActionTest.init(DashboardActionTest.java:53).......

I am trying to manually inject the EntityManager instance into the Action class that is being tested b/c otherwise I get nullpointerexception.

Here's the Test class code:

package example1;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

import org.testng.annotations.Configuration;
import org.testng.annotations.Test;

import com.h123.loantrack.DashboardAction;
import com.h123.loantrack.User;

public class DashboardActionTest
{	
	@Test
    public void testDashboardAction()

	{
		EntityManager em = getEntityManagerFactory().createEntityManager();
        //em.getTransaction().begin();
        
        User user = new User();
        user.setUserID(10471);
        
        DashboardAction action = new DashboardAction();
        
        action.setUser(user);
        action.setRSDB(em);
        
        assert "main".equals(action.findAppLoanRecords());
        
        assert "main".equals(action.findPQLoanRecords());
        
        assert "main".equals(action.findQRWLoanRecords());
        
        assert "main".equals(action.findWFLoanRecords());
        
        //em.getTransaction().commit();
        //em.close();
    }
    
    
    private EntityManagerFactory emf;
    
    public EntityManagerFactory getEntityManagerFactory()
    {
        return emf;
    }
    
    @Configuration(beforeTestClass=true)
    public void init() 
    {
        emf = Persistence.createEntityManagerFactory("RSDB");
    }
    
    @Configuration(afterTestClass=true)
    public void destroy()
    {
        emf.close();
    }
    

}

Anybody know how to fix this?

I found the following info from http://www.hibernate.org/hib_docs/entitymanager/reference/en/html/configuration.html:

When Persistence.createEntityManagerFactory() is called, the persistence implementation will search your classpath for any META-INF/persistence.xml files using the ClassLoader.getResource("META-INF/persistence.xml") method. Actually the Persistence class will look at all the Persistence Providers available in the classpath and ask each of them if they are responsible for the creation of the entity manager factory manager1. Each provider, from this list of resources, it will try to find an entity manager that matches the name you specify in the command line with what is specified in the persistence.xml file (of course the provider element must match the current persistent provider). If no persistence.xml with the correct name are found or if the expected persistence provider is not found, a PersistenceException is raised.  

So is my persistence.xml not in the classpath?  Running test suite inside Eclipse without JBoss running.

thanks.


View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4005982#4005982

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4005982



More information about the jboss-user mailing list