title: SEVERE: Exception looking up UserDatabase under key UserDatabase javax.naming.NameNotFoundException: Name [UserDatabase] is not bound in this Context
body: <p>im using TOMCAT 9 and latest hibernat jars with java 1.8<br>
  i create simple user in mysql and 1 table db called foo1<br>
  in my webapp in tomcat i configured based on examples online : </p>
  
  <p><strong>workspace\HibernateApp\src\hibernate.cfg.xml:</strong></p>
  
  <pre><code>&lt;?xml version='1.0' encoding='utf-8'?&gt;
  &lt;!DOCTYPE hibernate-configuration PUBLIC
          "-//Hibernate/Hibernate Configuration DTD//EN"
          "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"&gt;
  &lt;hibernate-configuration&gt;
      &lt;session-factory&gt;
  
          &lt;property name="show_sql"&gt;true&lt;/property&gt;
          &lt;property name="format_sql"&gt;true&lt;/property&gt;
          &lt;property name="dialect"&gt;org.hibernate.dialect.MySQLDialect&lt;/property&gt;
          &lt;property name="current_session_context_class"&gt;thread&lt;/property&gt;
          &lt;property name="hbm2ddl.auto"&gt;update&lt;/property&gt;
  
          &lt;property name="hibernate.max_fetch_depth"&gt;3&lt;/property&gt;
  
          &lt;property name="connection.datasource"&gt;java:comp/env/jdbc/foo1&lt;/property&gt;
  
          &lt;!-- Mapping files --&gt;
  
          &lt;!--mapping class="com.playground.myapp.model.User"/--&gt;
  
      &lt;/session-factory&gt;
  &lt;/hibernate-configuration&gt;
  </code></pre>
  
  <p><strong>workspace\HibernateApp\WebContent\META-INF\context.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  
  &lt;Context antiJARLocking="true" path="/"&gt;
      &lt;Resource
              name="jdbc/foo1"
              auth="Container"
              type="javax.sql.DataSource"
              username="foo1"
              password="12345"
              driverClassName="com.mysql.jdbc.Driver"
              url="jdbc:mysql://localhost:3306/foo1"
              maxActive="8"
              maxIdle="4"/&gt;
  
  &lt;/Context&gt;
  </code></pre>
  
  <p>Then im not sure way i need also to set up in server.xml the Resource but i did 
  as i saw developers doing it online   </p>
  
  <p><strong>workspace\Servers\Tomcat v9.0 Server at localhost-config\server.xml</strong></p>
  
  <pre><code>&lt;GlobalNamingResources&gt;
      &lt;!-- Editable user database that can also be used by
           UserDatabaseRealm to authenticate users
      --&gt;
      &lt;!-- Resource auth="Container" description="User database that can be updated and saved" factory="org.apache.catalina.users.MemoryUserDatabaseFactory" name="UserDatabase" pathname="conf/tomcat-users.xml" type="org.apache.catalina.UserDatabase"/--&gt;
     &lt;Resource
              name="jdbc/foo1"
              auth="Container"
              type="javax.sql.DataSource"
              username="foo1"
              password="12345"
              driverClassName="com.mysql.jdbc.Driver"
              url="jdbc:mysql://localhost:3306/foo1"
              maxActive="8"
              maxIdle="4"/&gt;
    &lt;/GlobalNamingResources&gt;
  </code></pre>
  
  <p>but i keep getting this runtime error:</p>
  
  <pre><code>SEVERE: Exception looking up UserDatabase under key UserDatabase
  javax.naming.NameNotFoundException: Name [UserDatabase] is not bound in this Context. Unable to find [UserDatabase].
      at org.apache.naming.NamingContext.lookup(NamingContext.java:817)
      at org.apache.naming.NamingContext.lookup(NamingContext.java:173)
      at org.apache.catalina.realm.UserDatabaseRealm.startInternal(UserDatabaseRealm.java:215)
      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
      at org.apache.catalina.realm.CombinedRealm.startInternal(CombinedRealm.java:245)
      at org.apache.catalina.realm.LockOutRealm.startInternal(LockOutRealm.java:115)
      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
      at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:926)
      at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:262)
      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
      at org.apache.catalina.core.StandardService.startInternal(StandardService.java:422)
      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
      at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:793)
      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
      at org.apache.catalina.startup.Catalina.start(Catalina.java:655)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
      at java.lang.reflect.Method.invoke(Unknown Source)
      at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:355)
      at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:495)
  </code></pre>