[jboss-user] [JBoss Seam] - EntityManager trouble

ErikSlagter do-not-reply at jboss.com
Thu Jan 10 09:50:47 EST 2008


I'm in some trouble with testing my DAO in Eclipse. I'm using TestNG and Eclipse europe together with Seam 2.0.0GA.

I have to got the following test funtion:

  |         @Test
  | 	public void test(){
  | 		dao = new PaymentDeviceDAO();
  | 		String terminalProvider = "Malle Japie";
  | 		String terminalId = "12345";
  | 		
  | 		device = dao.findById(terminalProvider, terminalId);
  | 		assert device != null;		
  | 	}
  | 	
  | 	private EntityManagerFactory emf;
  | 	@Out
  | 	EntityManager em;
  | 	
  | 	protected String datasourceJndiName;
  | 	public EntityManagerFactory getEntityManagerFactory(){
  | 		assert emf != null;
  | 	    return emf;
  | 	}
  | 
  | 	@BeforeClass
  | 	@Parameters("datasourceJndiName")
  | 	public void setDatasourceJndiName(String datasourceJndiName) {
  | 		this.datasourceJndiName = datasourceJndiName;
  | 		init();
  | 	}
  | 	
  | 	public void init(){
  | 	    emf = Persistence.createEntityManagerFactory(datasourceJndiName);
  | 	    em = emf.createEntityManager();
  | 	    assert emf != null;
  | 	}
  | 	
  | 	@AfterClass
  | 	public void destroy(){
  | 	    emf.close();
  | 	    assert emf.isOpen() == false;
  | 	}	
  | 

What is tries to do is find a PaymentDevice using the two arguments. Nothing special... 
datasourceJndiName is defined in the testng.xml filed as "testDb".
When I run this test I get the following Exception:
javax.persistence.PersistenceException: No Persistence provider for EntityManager named testDb

I tried to figure it out myself, by following the dvd example of seam and various forums.
I can't find out anymore where it goes all wrong!?

Can anybody help me?

My configs are defined as following:
persistence.xml

  | 
  |         <persistence-unit name="testDb">
  | 	  <provider>org.hibernate.ejb.HibernatePersistence</provider>
  | 	  <jta-data-source>java:/testDataSource</jta-data-source>
  | 	  <properties>
  | 	     <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
  | 	     <property name="hibernate.cache.use_query_cache" value="true"/>
  | 	     <property name="hibernate.show_sql" value="false"/>
  | 	
  | 	     <property name="jboss.entity.manager.factory.jndi.name" value="java:/testEntityManagerFactory" />
  | 	   </properties>
  | 	</persistence-unit>
  | 

components.xml
<persistence:managed-persistence-context name="entityManager"
  |                                       auto-create="true"
  |                        persistence-unit-jndi-name="java:/testEntityManagerFactory" />

mps-ds.xml
<local-tx-datasource>
  |       <jndi-name>testDataSource</jndi-name>
  |       <connection-url>jdbc:postgresql://localhost:5432/mps</connection-url>
  |       <driver-class>org.postgresql.Driver</driver-class>
  |       <user-name>postgres</user-name>
  |       <password>secretPassword:)</password>
  | <!-- 
  |       <exception-sorter-class-name>
  |          org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter
  |       </exception-sorter-class-name>
  |       <metadata>
  |          <type-mapping>mySQL</type-mapping>
  |       </metadata>
  | -->
  |    </local-tx-datasource>

hibernate.cfg.xml
<hibernate-configuration>
  |   <session-factory>
  | 
  |      <property name="show_sql">false</property>
  |     <property name="connection.datasource">java:/testDataSource</property>
  |     <property name="transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property>
  |     <property name="transaction.manager_lookup_class">org.hibernate.transaction.JBossTransactionManagerLookup</property>
  |     <property name="cache.provider_class">org.hibernate.cache.HashtableCacheProvider</property>
  |     <property name="hbm2ddl.auto">create-drop</property>
  |       
  |   </session-factory>
  | </hibernate-configuration>
  | 

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

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



More information about the jboss-user mailing list