JndiException ao usar o Hibernate 4.0 com o Tomcat 7 ao usar o persistence.xml

Estou usando o Hibernate 4.0 com um arquivo JPA persistence.xml no Tomcat 7. No Struts, apenas o Hibernate direto com alguns serviços do Jersey. Aqui está a exceção que estou correndo:

Caused by: org.hibernate.service.jndi.JndiException: Unable to lookup JNDI name [jdbc/MyDB]
    at org.hibernate.service.jndi.internal.JndiServiceImpl.locate(JndiServiceImpl.java:68)
    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:94)
    at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:904)
    ... 8 more
Caused by: javax.naming.NameNotFoundException: Name jdbc is not bound in this Context
    at org.apache.naming.NamingContext.lookup(NamingContext.java:820)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:154)
    at org.apache.naming.SelectorContext.lookup(SelectorContext.java:135)
    at javax.naming.InitialContext.lookup(InitialContext.java:396)
    at org.hibernate.service.jndi.internal.JndiServiceImpl.locate(JndiServiceImpl.java:65)
    ... 23 more

Eu vejo a nota sobre jbc não está vinculado neste contexto, mas estou confuso como isso está acontecendo. Estou implantando meu contexto em um context.xml específico do aplicativo, abaixo:

<?xml version='1.0' encoding='utf-8'?>
<Context>
    <Resource name="jdbc/MyDB" auth="Container" type="javax.sql.DataSource"
              maxActive="100" maxIdle="30" maxWait="10000"
              username="..." password="..." driverClassName="com.mysql.jdbc.Driver"
              url="jdbc:mysql://localhost:3306/mydb"/>
</Context>

E meu arquivo persistence.xml se parece com:

<persistence xmlns="http://java.sun.com/xml/ns/persistence"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
             version="2.0">

    <persistence-unit name="com.example.mysql" transaction-type="RESOURCE_LOCAL">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <non-jta-data-source>jdbc/MyDB</non-jta-data-source>
        <class>...</class>
        <properties>
            <property name="hibernate.connection.datasource" value="jdbc/MyDB"/>
            <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
            <property name="hibernate.id.new_generator_mappings" value ="true"/>
        </properties>
    </persistence-unit>
</persistence>

Finalmente, meu arquivo web.xml possui o recurso definido assim:

<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app>
    <display-name>My Web Application</display-name>
    <resource-ref>
        <description>DB Connection</description>
        <res-ref-name>jdbc/MyDB</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
    </resource-ref>
...
</web-app>

Quanto ao meu layout, aqui está como o meu arquivo de guerra está estruturado:

app.war
    + META-INF
        - context.xml
    + WEB-INF
        + classes
            + META-INF
                - persistence.xml
        + lib
        - web.xml

Algumas notas menores:

Usar um contexto global versus um contexto específico de aplicativo não faz diferença.O código que tenta instanciar uma instância EntityManager está em um arquivo JAR no diretório lib (parte de uma construção Maven de vários projetos), mas o XML de persistência está no aplicativo da web principal, conforme descrito acima.Eu posso ver a fonte de dados JNDI no Tomcat e posso consultá-lo usandopsi-sonda, ou seja, posso acessar as informações de conexão e executar consultas SQL com êxito na fonte de dados.

questionAnswers(1)

yourAnswerToTheQuestion