title: Could not open JPA EntityManager for transaction [...] A connection could not be obtained for driver class "null" and URL "null"
body: <p>I'm having an issue connecting to my DB in a Spring based web application hosted on Tomcat 7.  In my search for a solution I've found many people who have had similar issues but none of their solutions seem to work for me. I'm developing in Eclipse (RAD 8.5).</p>
  
  <p>Here is the stack trace:</p>
  
  <pre><code>2015-05-18_13:36:49.625 [http-bio-8080-exec-3] ERROR c.m.g.s.TenancyDetailsServiceImpl - Error condition: Could not open JPA EntityManager for transaction; nested exception is &lt;openjpa-2.3.0-r422266:1540826 nonfatal general error&gt; org.apache.openjpa.persistence.PersistenceException: There were errors initializing your configuration: &lt;openjpa-2.3.0-r422266:1540826 fatal user error&gt; org.apache.openjpa.util.UserException: A connection could not be obtained for driver class "null" and URL "null".  You may have specified an invalid URL.
  at org.apache.openjpa.jdbc.schema.DataSourceFactory.newConnectException(DataSourceFactory.java:255)
  at org.apache.openjpa.jdbc.schema.DataSourceFactory.installDBDictionary(DataSourceFactory.java:241)
  at org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl.getConnectionFactory(JDBCConfigurationImpl.java:733)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:94)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:55)
  at java.lang.reflect.Method.invoke(Method.java:619)
  at org.apache.openjpa.lib.conf.ConfigurationImpl.instantiateAll(ConfigurationImpl.java:310)
  at org.apache.openjpa.conf.OpenJPAConfigurationImpl.instantiateAll(OpenJPAConfigurationImpl.java:1670)
  at org.apache.openjpa.kernel.AbstractBrokerFactory.makeReadOnly(AbstractBrokerFactory.java:651)
  at org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker(AbstractBrokerFactory.java:203)
  at org.apache.openjpa.kernel.DelegatingBrokerFactory.newBroker(DelegatingBrokerFactory.java:155)
  at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:226)
  at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:153)
  at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:59)
  at org.springframework.orm.jpa.JpaTransactionManager.createEntityManagerForTransaction(JpaTransactionManager.java:445)
  at org.springframework.orm.jpa.JpaTransactionManager.doBegin(JpaTransactionManager.java:366)
  at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:371)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:94)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:55)
  at java.lang.reflect.Method.invoke(Method.java:619)
  at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:319)
  at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:196)
  at com.sun.proxy.$Proxy56.getTransaction(Unknown Source)
  at org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:336)
  at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:105)
  at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
  at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
  at com.sun.proxy.$Proxy39.getTenancyDetailsWithTenantCode(Unknown Source)
  at com.m.gsp.serviceimpl.TenancyDetailsServiceImpl.getTenancyDetailsWithTenantCode(TenancyDetailsServiceImpl.java:70)
  at com.m.gsp.helper.TenancyDelegate.getTenancyDetailsWithTenantCode(TenancyDelegate.java:42)
  at com.m.gsp.utils.WebUtils.fetchTenancyDetails(WebUtils.java:609)
  at com.m.gsp.controllers.AuthenticationController.renderLoginPage(AuthenticationController.java:128)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:94)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:55)
  at java.lang.reflect.Method.invoke(Method.java:619)
  at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:213)
  at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:126)
  at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:96)
  at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:617)
  at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:578)
  at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
  at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)
  at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
  at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
  at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
  at com.m.gsp.tenancy.TenantDispatcherServlet.service(TenantDispatcherServlet.java:101)
  at com.m.gsp.tenancy.TenantDispatcherServletProxy.service(TenantDispatcherServletProxy.java:82)
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
  at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
  at com.m.gsp.logging.MDCServletFilter.doFilter(MDCServletFilter.java:140)
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
  at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:186)
  at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160)
  at com.m.gsp.tenancy.security.TenantDelegatingFilterProxy.doFilter(TenantDelegatingFilterProxy.java:65)
  at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
  at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
  at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
  at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
  at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
  at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
  at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503)
  at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
  at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
  at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
  at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
  at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421)
  at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070)
  at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
  at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:314)
  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1176)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
  at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
  at java.lang.Thread.run(Thread.java:795)
  </code></pre>
  
  <p>Caused by: org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class 'com.microsoft.sqlserver.jdbc.SQLServerDriver' for connect URL 'jdbc:sqlserver:AX-RISCVMSQL74\SQL74:1435;databaseName=GSPVN;'
      at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1452)
      at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1371)
      at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
      at org.apache.openjpa.lib.jdbc.DelegatingDataSource.getConnection(DelegatingDataSource.java:116)
      at org.apache.openjpa.lib.jdbc.DecoratingDataSource.getConnection(DecoratingDataSource.java:93)
      at org.apache.openjpa.jdbc.schema.DataSourceFactory.installDBDictionary(DataSourceFactory.java:233)
      ... 84 more
  Caused by: java.sql.SQLException: No suitable driver
      at java.sql.DriverManager.getDriver(DriverManager.java:289)
      at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1437)
      ... 89 more</p>
  
  <p>Context.xml:</p>
  
  <pre><code>&lt;Resource name="jdbc/salesvietnamMssqlGspDS"
  auth="Container"
  factory="org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory"
  driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver"
  type="javax.sql.DataSource"
  maxActive="50"
  maxIdle="10"
  maxWait="15000"
  username="x"
  password="y"
  url="jdbc:sqlserver:server/instance:port;databaseName=dbname;"
  removeAbandoned="true"
  removeAbandonedTimeout="30"
  logAbandoned="true" /&gt; 
  </code></pre>
  
  <p>Application's WEB-INF/web.xml:</p>
  
  <pre><code>&lt;resource-ref&gt;
  &lt;description&gt;JDBCconnection&lt;/description&gt;
  &lt;res-ref-name&gt;jdbc/salesvietnamMssqlGspDS&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;
  </code></pre>
  
  <p></p>
  
  <p>I even put the same resource-ref in the server's web.xml as well.</p>
  
  <p>sqljdbc4.jar is present in the server's <code>/lib</code> directory. 
  I added it to the Classpath under user entries in the run configurations menu.
  I even tried adding it in the build path and deployment assembly, I've verified it does show up in WEB-INF/lib.</p>
  
  <p>None of the above have had any effect.</p>
  
  <p>I read about needing to register the driver using <code>Class.forName("something.jdbc.driver.YourFubarDriver");</code> but then I also read that was no longer necessary with JDBC4.</p>
  
  <p>Any ideas?</p>