Hi All,

I'm getting exceptions when im trying to obtain entitymanagerfactory reference via JNDI.

My project environment is :
JBoss 4.2.2
Spring 2.5.6
Hibernate 3.2.6

As far i know(after googling and reading blogs), there is two ways by which you can obtain entitymanagerfactory reference through JNDI in JBoss

1) Using <persistence-unit-ref> in any of the J2EE deployment descriptor (i'm using web.xml)

or

2) Using property jboss.entity.manager.factory.jndi.name in the persistent.xml file.

The persistenent.xml file should be in the classpath under META-INF.

I've tried both the approaches , but for both i get the same exception.

HTML Code:
javax.naming.NameNotFoundException: MyAppPU not bound

Find below snippets of the various artifacts.

Using Approach 1)

Web.xml
HTML Code:
<persistence-unit-ref>
    <description> Persistence unit for the application. </description>
    <persistence-unit-ref-name>MyAppPU</persistence-unit-ref-name>
    <persistence-unit-name> MyAppPU</persistence-unit-name>
</persistence-unit-ref>
applicationContext.xml
HTML Code:
  <jee:jndi-lookup id="entityManagerFactory" jndi-name="MyAppPU"/>
The JNDI name i tried using are:
- java:/MyAppPU
- java:comp/env/MyAppPU


Using Approach 2)

persistent.xml
HTML Code:
<persistence-unit name="MyAppPU" transaction-type="RESOURCE_LOCAL">
	<properties>
	<property name="hibernate.dialect"   
                    value="org.hibernate.dialect.Oracle10gDialect" />
	<property name="jboss.entity.manager.factory.jndi.name"           
                    value="MyAppPU" />
	<property name="hibernate.hbm2ddl.auto" value="update" />
	<property name="hibernate.archive.autodetection" value="class" />
	<property name="hibernate.show_sql" value="true" />
	<property name="hibernate.format_sql" value="true" />
		</properties>
	</persistence-unit>

applicationContext.xml
HTML Code:
  <jee:jndi-lookup id="entityManagerFactory" jndi-name="MyAppPU"/>
The JNDI name i tried using are:
- java:/MyAppPU
- java:comp/env/MyAppPU

But as i said they both throw javax.naming.NameNotFoundException: MyAppPU not bound

Can any one guide me as to where im going wrong or which piece i'm missing.

Thanks
Ved