EntityManagerFactory is null in jndi.  No errors, no warnings, notta just null 
or "not found" etc. 

Yep I've seen posts on this, but no good answer. 

jboss-4.0.4.GA

So far my SLSB beans work remotely for unit tests.  

But ... 

How do you get an EntitManagerFactory from outside the container? 

JNDI always returns either not found or null. 

In my META-INF/persistence.xml file (of the deployed test jar): 

<?xml version="1.0" encoding="UTF-8"?>
  | <persistence>
  |    <persistence-unit name="fudb">
  |       <jta-data-source>java:/MySqlDS</jta-data-source>
  |       <exclude-unlisted-classes>false</exclude-unlisted-classes>
  |       <class>com.fubar.ads.clicks.model.DataDemographic</class>
  |       <properties>
  |               <property name="hibernate.hbm2ddl.auto" value="update"/>
  |               <property name="hibernate.dialect" 
value="org.hibernate.dialect.MySQLDialect"/>
  |               <property name="jboss.entity.manager.jndi.name" value="fudb"/>
  |               <property name="jboss.entity.manager.factory.jndi.name" 
value="fudbFactory"/>
  |        </properties>
  |    </persistence-unit>
  | </persistence>


All of the following test methods fail: 

        
  | // testEMF() blows with javax.persistence.PersistenceException: No 
Persistence provider for EntityManager named
  | 
  |     public void testEMF() throws Exception  
  |     {
  |             EntityManagerFactory emf = 
Persistence.createEntityManagerFactory("fudb"); 
  |             assertNotNull("EntityManagerFactory not accessible.", emf );
  |     }
  | 
  |     public void testEMF2() throws Exception  
  |     {
  |             InitialContext ctx = getInitialContext(); 
  |             Object em = ctx.lookup("java:/fudb");
  |             assertNotNull("obj is null.", em );
  |     }
  | 
  |     public void testEMF2b() throws Exception  
  |     {
  |             InitialContext ctx = getInitialContext(); 
  |             Object em = ctx.lookup("fudb");
  |             assertNotNull("obj is null.", em );
  |     }
  | 
  |     public void testEMF3() throws Exception  
  |     {
  |             InitialContext ctx = getInitialContext(); 
  |             Object em = ctx.lookup("java:/fudbFactory");
  |             assertNotNull("obj is null.", em );
  |     }
  | 
  |     public void testEMF3b() throws Exception  
  |     {
  |             InitialContext ctx = getInitialContext(); 
  |             Object em = ctx.lookup("fudbFactory");
  |             assertNotNull("obj is null.", em );
  |     }
  | 
  |     public static InitialContext getInitialContext() throws Exception
  |     {
  |             Hashtable props = getInitialContextProperties();
  |                     return new InitialContext(props);
  |     }
  | 
  |     private static Hashtable getInitialContextProperties()
  |     {
  |             Hashtable<String, Object> props = new Hashtable<String, 
Object>();
  |             props.put("java.naming.factory.initial", 
"org.jnp.interfaces.NamingContextFactory" );
  |                     //"org.jnp.interfaces.LocalOnlyContextFactory"
  |             props.put("java.naming.factory.url.pkgs", 
"org.jboss.naming:org.jnp.interfaces");
  |                     props.put("java.naming.provider.url", 
"jnp://localhost:1099/");
  |                     return props;
  |     }
  | 

And in JNDIView for Global Bindings: 

fudbFactory: org.jboss.ejb3.entity.InjectedEntityManagerFactory:Reference Class 
Name: org.jboss.ejb3.entity.InjectedEntityManagerFactory Type: nns Content: 
/fudbFactory
  | 
  | fudb: org.jboss.ejb3.entity.TransactionScopedEntityManager:Reference Class 
Name: org.jboss.ejb3.entity.TransactionScopedEntityManager Type: nns Content: 
/fudb
  | 

I've tried lots of random things due to my lack of full docs, so maybe my 
approach totally wrong ... Why null in jndi?  Is this a bug?  

-Jud


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

Reply to the post : 
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3976196
_______________________________________________
jboss-user mailing list
jboss-user@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/jboss-user

Reply via email to