title: FAIL - Application at context path /MyProject could not be started (JndiException and NameNotFoundException)
body: <p>I am trying to deploy my project on Tomcat 7. I included</p>
  
  <p>at tomcat/config/context.xml:</p>
  
  <pre><code>&lt;ResourceLink name="jdbc/MyProjectDS"
               global="jdbc/MyProjectDS"
                type="javax.sql.DataSource" /&gt;
  </code></pre>
  
  <p>and</p>
  
  <p>at tomcat/config/server.xml:</p>
  
  <pre><code>&lt;Resource name="jdbc/MyProjectDS" auth="Container"
      type="javax.sql.DataSource"
      maxActive="100" maxIdle="5" maxWait="30000"
      username="username" password="password"
      driverClassName="com.mysql.jdbc.Driver"
      testOnBorrow="true"
      validationQuery="Select 1"
      url="jdbc:mysql://10.15.101.73:3306/myproject?autoReconnect=true"/&gt;
  </code></pre>
  
  <p>but it returns the exceptions as follow:</p>
  
  <pre><code>Aug 09, 2017 2:41:02 PM org.apache.catalina.core.StandardContext filterStart
  SEVERE: Exception starting filter naviox
  javax.persistence.PersistenceException: Unable to build entity manager factory
      at org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:83)
      at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:54)
      at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:55)
      at org.openxava.jpa.XPersistence.getEntityManagerFactory(XPersistence.java:197)
      at org.openxava.jpa.XPersistence.createManager(XPersistence.java:112)
      at org.openxava.jpa.XPersistence.openManager(XPersistence.java:128)
      at org.openxava.jpa.XPersistence.getManager(XPersistence.java:98)
      at com.openxava.naviox.impl.DB.isAutoUpdateSchema(DB.java:173)
      at com.openxava.naviox.impl.DB.createDB(DB.java:153)
      at com.openxava.naviox.impl.DB.init(DB.java:32)
      at com.openxava.naviox.Modules.init(Modules.java:38)
      at com.openxava.naviox.web.NaviOXFilter.init(NaviOXFilter.java:22)
      at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:281)
      at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:262)
      at org.apache.catalina.core.ApplicationFilterConfig.&lt;init&gt;(ApplicationFilterConfig.java:107)
      at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4746)
      at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5399)
      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
      at org.apache.catalina.manager.ManagerServlet.start(ManagerServlet.java:1256)
      at org.apache.catalina.manager.HTMLManagerServlet.start(HTMLManagerServlet.java:714)
      at org.apache.catalina.manager.HTMLManagerServlet.doPost(HTMLManagerServlet.java:219)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
      at org.apache.catalina.filters.CsrfPreventionFilter.doFilter(CsrfPreventionFilter.java:213)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
      at org.apache.catalina.filters.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:108)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
      at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:581)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
      at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:947)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
      at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1009)
      at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
      at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
      at java.lang.Thread.run(Thread.java:744)
  Caused by: org.hibernate.engine.jndi.JndiException: Unable to lookup JNDI name [java://comp/env/jdbc/MyProjectDS]
      at org.hibernate.engine.jndi.internal.JndiServiceImpl.locate(JndiServiceImpl.java:117)
      at org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.configure(DatasourceConnectionProviderImpl.java:115)
      at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:111)
      at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:234)
      at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:206)
      at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.buildJdbcConnectionAccess(JdbcServicesImpl.java:260)
      at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:94)
      at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:111)
      at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:234)
      at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:206)
      at org.hibernate.cfg.Configuration.buildTypeRegistrations(Configuration.java:1887)
      at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1845)
      at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:857)
      at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:850)
      at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:425)
      at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:849)
      at org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:75)
      ... 44 more
  Caused by: javax.naming.NameNotFoundException: Name [jdbc/MyProjectDS] is not bound in this Context. Unable to find [jdbc].
      at org.apache.naming.NamingContext.lookup(NamingContext.java:820)
      at org.apache.naming.NamingContext.lookup(NamingContext.java:168)
      at org.apache.naming.factory.ResourceLinkFactory.getObjectInstance(ResourceLinkFactory.java:94)
      at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:321)
      at org.apache.naming.NamingContext.lookup(NamingContext.java:843)
      at org.apache.naming.NamingContext.lookup(NamingContext.java:154)
      at org.apache.naming.NamingContext.lookup(NamingContext.java:831)
      at org.apache.naming.NamingContext.lookup(NamingContext.java:154)
      at org.apache.naming.NamingContext.lookup(NamingContext.java:831)
      at org.apache.naming.NamingContext.lookup(NamingContext.java:154)
      at org.apache.naming.NamingContext.lookup(NamingContext.java:831)
      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:415)
      at org.hibernate.engine.jndi.internal.JndiServiceImpl.locate(JndiServiceImpl.java:114)
      ... 60 more
  </code></pre>
  
  <p>At myproject/hibernate.cfg.xml, I have the following codes:</p>
  
  <pre><code>&lt;hibernate-configuration&gt;
  
      &lt;session-factory&gt;
  
          &lt;!-- Tomcat + Hypersonic --&gt;
          &lt;property name="hibernate.connection.datasource"&gt;java://comp/env/jdbc/MyProjectDS&lt;/property&gt;
          &lt;property name="hibernate.dialect"&gt;org.hibernate.dialect.MySQLDialect&lt;/property&gt;
          &lt;property name="hibernate.jdbc.use_get_generated_keys"&gt;false&lt;/property&gt;     
          &lt;property name="hibernate.show_sql"&gt;false&lt;/property&gt;
          &lt;property name="hibernate.connection.release_mode"&gt;after_transaction&lt;/property&gt;
  
          &lt;!-- Use the C3P0 connection pool provider --&gt;
          &lt;property name="hibernate.connection.provider_class"&gt;org.hibernate.connection.C3P0ConnectionProvider&lt;/property&gt;
          &lt;property name="hibernate.c3p0.min_size"&gt;2&lt;/property&gt;
          &lt;property name="hibernate.c3p0.max_size"&gt;50&lt;/property&gt;
          &lt;property name="hibernate.c3p0.timeout"&gt;300&lt;/property&gt;
          &lt;property name="hibernate.c3p0.max_statements"&gt;50&lt;/property&gt;
          &lt;property name="hibernate.c3p0.idle_test_period"&gt;3000&lt;/property&gt;
          &lt;property name="hibernate.c3p0.validate"&gt;true&lt;/property&gt;
  
          &lt;property name="hibernate.c3p0.preferredTestQuery"&gt;SELECT 1&lt;/property&gt;
          &lt;property name="hibernate.c3p0.testConnectionOnCheckin"&gt;true&lt;/property&gt;
          &lt;property name="hibernate.c3p0.testConnectionOnCheckout"&gt;false&lt;/property&gt;
          &lt;property name="hibernate.c3p0.idleConnectionTestPeriod"&gt;300&lt;/property&gt; &lt;!-- 5 minutes --&gt;
  
      &lt;/session-factory&gt;
  
  &lt;/hibernate-configuration&gt;
  </code></pre>
  
  <p>At persistence.xml:</p>
  
  <pre><code>&lt;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_1_0.xsd"
               version="1.0"&gt;
  
      &lt;!-- Tomcat + Hypersonic --&gt;
      &lt;persistence-unit name="default"&gt;
          &lt;provider&gt;org.hibernate.jpa.HibernatePersistenceProvider&lt;/provider&gt;
          &lt;non-jta-data-source&gt;java://comp/env/jdbc/AdunFormsDS&lt;/non-jta-data-source&gt;
          &lt;class&gt;org.openxava.session.GalleryImage&lt;/class&gt;
          &lt;class&gt;org.openxava.web.editors.DiscussionComment&lt;/class&gt;
          &lt;properties&gt;
              &lt;property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/&gt;
              &lt;property name="hibernate.hbm2ddl.auto" value="update"/&gt;
              &lt;property name="hibernate.connection.release_mode" value="after_transaction"/&gt;
          &lt;/properties&gt;
      &lt;/persistence-unit&gt;    
  &lt;/persistence&gt;
  </code></pre>
  
  <p>I have no idea why these exceptions appear since this is my first time deploying a project on a tomcat server. I tried to google the solution but none of them solve my problem. I hope that someone can guide me. Thanks in advance.</p>