title: Hibernate 5.0 dialect auto detection not working with JNDI on Tomcat
body: <p>I'am trying to connect to a JNDI datasource specified in Tomcat's server.xml.
  My hibernate.cfg.xml looks like this:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-configuration"&gt;
  &lt;hibernate-configuration&gt;
      &lt;session-factory&gt;
          &lt;property name="hibernate.connection.datasource"&gt;java:comp/env/jdbc/myDB&lt;/property&gt;
          &lt;property name="hibernate.hbm2ddl.auto"&gt;create&lt;/property&gt;
          &lt;property name="hibernate.dialect"&gt;org.hibernate.dialect.org.hibernate.dialect.DerbyDialect&lt;/property&gt;
          &lt;property name="hibernate.current_session_context_class"&gt;org.hibernate.context.internal.ThreadLocalSessionContext&lt;/property&gt;
          &lt;mapping class="com.gigatronik.bosch.plugin.remoteserver.db.ConnectEntity"/&gt;
      &lt;/session-factory&gt;
  
  &lt;/hibernate-configuration&gt;
  </code></pre>
  
  <p>Everything works well (so I assume my configuration is correct) until I remove the <code>hibernate.dialect</code> property - which implicitly enables dialect auto detection:</p>
  
  <pre><code>WARN [http-apr-8080-exec-9] org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService HHH000342: Could not obtain connection to query metadata : Cannot create JDBC driver of class '' for connect URL 'null'
  </code></pre>
  
  <p>and</p>
  
  <pre><code>Caused by: org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set
  at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.determineDialect(DialectFactoryImpl.java:100) ~[hibernate-core-5.0.5.Final.jar:5.0.5.Final]
  at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.buildDialect(DialectFactoryImpl.java:54) ~[hibernate-core-5.0.5.Final.jar:5.0.5.Final]
  at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:137) ~[hibernate-core-5.0.5.Final.jar:5.0.5.Final]
  at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:35) ~[hibernate-core-5.0.5.Final.jar:5.0.5.Final]
  at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:88) ~[hibernate-core-5.0.5.Final.jar:5.0.5.Final]
  at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:234) ~[hibernate-core-5.0.5.Final.jar:5.0.5.Final]
  ... 78 more
  </code></pre>
  
  <p>With Jetty the auto discovery feature works very well. Seems like only Apache Tomcat has this problem. How to enable auto detection with Tomcat?</p>
  
  <p><strong>Update:</strong>
  My Tomcat configuration:</p>
  
  <pre><code>...
  &lt;GlobalNamingResources&gt;
  ...
  
  &lt;Resource name="jdbc/myDB" auth="Container" type="javax.sql.DataSource"
  driverClassName="org.apache.derby.jdbc.EmbeddedDriver" 
  url="jdbc:derby:myDB;create=true"
  maxTotal="100" maxIdle="30" maxWaitMillis="10000" /&gt;
  ...
  &lt;/GlobalNamingResources&gt;
  </code></pre>