title: Initial SessionFactory creation failed.org.hibernate.HibernateException: Could not find datasource
body: <p>I am getting this error when getting sessionfactory from jboss JNDI and here is my source code.I have tried several times with many modifications but it has been not solved.
  Thanks in advance.</p>
  
  <h2>mysql-ds</h2>
  
  <p>which is placed in jboss default deploy folder.</p>
  
  <pre><code>&lt;datasources&gt;
  &lt;local-tx-datasource&gt;
  &lt;jndi-name&gt;jdbc/NeuraDS&lt;/jndi-name&gt;
  &lt;connection-url&gt;jdbc:mysql://localhost:3306/neurahmis&lt;/connection-url&gt;
  &lt;driver-class&gt;com.mysql.jdbc.Driver&lt;/driver-class&gt;
  &lt;user-name&gt;admin&lt;/user-name&gt;
  &lt;password&gt;admin@123&lt;/password&gt;
  &lt;min-pool-size&gt;5&lt;/min-pool-size&gt;
  &lt;max-pool-size&gt;1000&lt;/max-pool-size&gt;
  &lt;exception-sorter-class-   name&gt;org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter&lt;/exception-sorter-class-name&gt;  
  &lt;/local-tx-datasource&gt;
  &lt;/datasources&gt;
  </code></pre>
  
  <h2>web.xml</h2>
  
  <p>Added in web.xml for datasource</p>
  
  <pre><code>&lt;resource-ref&gt;
  &lt;description&gt;Database connection resource&lt;/description&gt;   
  &lt;res-ref-name&gt;Neura&lt;/res-ref-name&gt;
  &lt;res-type&gt;javax.sql.DataSource&lt;/res-type&gt;
  &lt;res-auth&gt;Container&lt;/res-auth&gt;
  &lt;res-sharing-scope&gt;Shareable&lt;/res-sharing-scope&gt;
  &lt;/resource-ref&gt;
  </code></pre>
  
  <h2>jboss-web.xml</h2>
  
  <p>Added in jboss-web.xml for jndi</p>
  
  <pre><code>&lt;jboss-web&gt;
  &lt;context-root&gt;/neurads&lt;/context-root&gt;
  &lt;resource-ref&gt;
  &lt;res-ref-name&gt;Neura&lt;/res-ref-name&gt;
  &lt;res-type&gt;javax.sql.DataSource&lt;/res-type&gt;
  &lt;jndi-name&gt;java:jdbc/NeuraDS&lt;/jndi-name&gt;
  &lt;/resource-ref&gt;
  &lt;/jboss-web&gt;
  </code></pre>
  
  <h2>hibernate.cfg.xml</h2>
  
  <p>These are my hibernate properties. </p>
  
  <pre><code>&lt;property name="hibernate.connection.datasource"&gt;java:/jdbc/NeuraDs&lt;/property&gt;
  &lt;property name="dialect"&gt;org.hibernate.dialect.MySQLDialect&lt;/property&gt; 
  &lt;property name="connection.pool_size"&gt;1&lt;/property&gt;
  &lt;property name="current_session_context_class"&gt;thread&lt;/property&gt;
  &lt;property name="cache.provider_class"&gt;org.hibernate.cache.NoCacheProvider&lt;/property&gt;
  &lt;property name="show_sql"&gt;true&lt;/property&gt;
  </code></pre>
  
  <h2>HibernateUtil.java</h2>
  
  <p>To obtain the session factory</p>
  
  <pre><code>sessionFactory=new Configuration().configure("hibernate.cfg.xml").buildSessionFactory();
  </code></pre>