title: Unable to connect to postgres SQL
body: <p>I'm using <code>Spring + Maven + Hibernate</code> and want to run tests in a <code>PostgreSQL</code> environment.</p>
  
  <p>After adding the proper dependencies and changing my xml files I'm getting the following error when running <code>mvn clean install</code> in cmd:</p>
  
  <pre><code>Coult not open JPA EntityManager for transaction; nested exception is javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Cannot open connection
  </code></pre>
  
  <p>And the output log of the test is something like:</p>
  
  <pre><code> Tests run: 9, Failures: 0, Errors: 9, Skipped: 0, Time elapsed: 23.695 sec &lt;&lt;&lt; FAILURE!
  testFlush(com.mms.pone.portal.domain.AccountAllocationIntegrationTest)  Time elapsed: 15.432 sec  &lt;&lt;&lt; ERROR!
  org.springframework.transaction.CannotCreateTransactionException: Could not open JPA EntityManager for transaction; nested exception is javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Cannot open connection
      at org.springframework.orm.jpa.JpaTransactionManager.doBegin(JpaTransactionManager.java:427)
      at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:371)
      at org.springframework.test.context.transaction.TransactionalTestExecutionListener$TransactionContext.startTransaction(TransactionalTestExecutionListener.java:513)
      at org.springframework.test.context.transaction.TransactionalTestExecutionListener.startNewTransaction(TransactionalTestExecutionListener.java:271)
      at org.springframework.test.context.transaction.TransactionalTestExecutionListener.beforeTestMethod(TransactionalTestExecutionListener.java:164)
      at org.springframework.test.context.TestContextManager.beforeTestMethod(TestContextManager.java:358)
      at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:73)
      at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:83)
      at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
      at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)
      at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
      at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
      at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
      at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
      at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
      at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
      at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
      at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
      at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
      at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174)
      at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:53)
      at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:123)
      at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:104)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:601)
      at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:164)
      at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:110)
      at org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:172)
      at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcessWhenForked(SurefireStarter.java:104)
      at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:70)
  Caused by: javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Cannot open connection
      at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1387)
      at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1315)
      at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:1397)
      at org.hibernate.ejb.TransactionImpl.begin(TransactionImpl.java:63)
      at org.springframework.orm.jpa.DefaultJpaDialect.beginTransaction(DefaultJpaDialect.java:70)
      at org.springframework.orm.jpa.JpaTransactionManager.doBegin(JpaTransactionManager.java:377)
      ... 31 more
  Caused by: org.hibernate.exception.GenericJDBCException: Cannot open connection
      at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:140)
      at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:128)
      at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
      at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:52)
      at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:449)
      at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:167)
      at org.hibernate.jdbc.JDBCContext.connection(JDBCContext.java:160)
      at org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:81)
      at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1473)
      at org.hibernate.ejb.TransactionImpl.begin(TransactionImpl.java:60)
      ... 33 more
  Caused by: org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Connection refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.)
      at org.apache.commons.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1549)
      at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1388)
      at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
      at org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider.getConnection(InjectedDataSourceConnectionProvider.java:71)
      at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:446)
      ... 38 more
  Caused by: org.postgresql.util.PSQLException: Connection refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
      at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:136)
      at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:66)
      at org.postgresql.jdbc2.AbstractJdbc2Connection.&lt;init&gt;(AbstractJdbc2Connection.java:125)
      at org.postgresql.jdbc3.AbstractJdbc3Connection.&lt;init&gt;(AbstractJdbc3Connection.java:30)
      at org.postgresql.jdbc3g.AbstractJdbc3gConnection.&lt;init&gt;(AbstractJdbc3gConnection.java:22)
      at org.postgresql.jdbc4.AbstractJdbc4Connection.&lt;init&gt;(AbstractJdbc4Connection.java:30)
      at org.postgresql.jdbc4.Jdbc4Connection.&lt;init&gt;(Jdbc4Connection.java:24)
      at org.postgresql.Driver.makeConnection(Driver.java:393)
      at org.postgresql.Driver.connect(Driver.java:267)
      at org.apache.commons.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:38)
      at org.apache.commons.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:582)
      at org.apache.commons.dbcp.BasicDataSource.validateConnectionFactory(BasicDataSource.java:1556)
      at org.apache.commons.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1545)
      ... 42 more
  Caused by: java.net.ConnectException: Connection refused: connect
      at java.net.DualStackPlainSocketImpl.connect0(Native Method)
      at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:69)
      at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
      at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
      at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
      at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:157)
      at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:391)
      at java.net.Socket.connect(Socket.java:579)
      at java.net.Socket.connect(Socket.java:528)
      at java.net.Socket.&lt;init&gt;(Socket.java:425)
      at java.net.Socket.&lt;init&gt;(Socket.java:208)
      at org.postgresql.core.PGStream.&lt;init&gt;(PGStream.java:62)
      at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:76)
      ... 54 more
  testMarkerMethod(com.mms.pone.portal.domain.AccountAllocationIntegrationTest)  Time elapsed: 1.003 sec  &lt;&lt;&lt; ERROR!
  org.springframework.transaction.CannotCreateTransactionException: Could not open JPA EntityManager for transaction; nested exception is javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Cannot open connection
      at org.springframework.orm.jpa.JpaTransactionManager.doBegin(JpaTransactionManager.java:427)
      at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:371)
      at org.springframework.test.context.transaction.TransactionalTestExecutionListener$TransactionContext.startTransaction(TransactionalTestExecutionListener.java:513)
      at org.springframework.test.context.transaction.TransactionalTestExecutionListener.startNewTransaction(TransactionalTestExecutionListener.java:271)
      at org.springframework.test.context.transaction.TransactionalTestExecutionListener.beforeTestMethod(TransactionalTestExecutionListener.java:164)
      at org.springframework.test.context.TestContextManager.beforeTestMethod(TestContextManager.java:358)
      at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:73)
      at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:83)
      at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
      at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)
      at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
      at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
      at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
      at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
      at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
      at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
      at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
      at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
      at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
      at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174)
      at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:53)
      at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:123)
      at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:104)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:601)
      at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:164)
      at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:110)
      at org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:172)
      at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcessWhenForked(SurefireStarter.java:104)
      at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:70)
  Caused by: javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Cannot open connection
      at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1387)
      at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1315)
      at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:1397)
      at org.hibernate.ejb.TransactionImpl.begin(TransactionImpl.java:63)
      at org.springframework.orm.jpa.DefaultJpaDialect.beginTransaction(DefaultJpaDialect.java:70)
      at org.springframework.orm.jpa.JpaTransactionManager.doBegin(JpaTransactionManager.java:377)
      ... 31 more
  Caused by: org.hibernate.exception.GenericJDBCException: Cannot open connection
      at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:140)
      at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:128)
      at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
      at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:52)
      at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:449)
      at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:167)
      at org.hibernate.jdbc.JDBCContext.connection(JDBCContext.java:160)
      at org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:81)
      at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1473)
      at org.hibernate.ejb.TransactionImpl.begin(TransactionImpl.java:60)
      ... 33 more
  Caused by: org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Connection refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.)
      at org.apache.commons.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1549)
      at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1388)
      at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
      at org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider.getConnection(InjectedDataSourceConnectionProvider.java:71)
      at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:446)
      ... 38 more
  Caused by: org.postgresql.util.PSQLException: Connection refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
      at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:136)
      at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:66)
      at org.postgresql.jdbc2.AbstractJdbc2Connection.&lt;init&gt;(AbstractJdbc2Connection.java:125)
      at org.postgresql.jdbc3.AbstractJdbc3Connection.&lt;init&gt;(AbstractJdbc3Connection.java:30)
      at org.postgresql.jdbc3g.AbstractJdbc3gConnection.&lt;init&gt;(AbstractJdbc3gConnection.java:22)
      at org.postgresql.jdbc4.AbstractJdbc4Connection.&lt;init&gt;(AbstractJdbc4Connection.java:30)
      at org.postgresql.jdbc4.Jdbc4Connection.&lt;init&gt;(Jdbc4Connection.java:24)
      at org.postgresql.Driver.makeConnection(Driver.java:393)
      at org.postgresql.Driver.connect(Driver.java:267)
      at org.apache.commons.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:38)
      at org.apache.commons.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:582)
      at org.apache.commons.dbcp.BasicDataSource.validateConnectionFactory(BasicDataSource.java:1556)
      at org.apache.commons.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1545)
      ... 42 more
  Caused by: java.net.ConnectException: Connection refused: connect
      at java.net.DualStackPlainSocketImpl.connect0(Native Method)
      at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:69)
      at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
      at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
      at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
      at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:157)
      at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:391)
      at java.net.Socket.connect(Socket.java:579)
      at java.net.Socket.connect(Socket.java:528)
      at java.net.Socket.&lt;init&gt;(Socket.java:425)
      at java.net.Socket.&lt;init&gt;(Socket.java:208)
      at org.postgresql.core.PGStream.&lt;init&gt;(PGStream.java:62)
      at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:76)
      ... 54 more
  testFindAccountAllocation(com.mms.pone.portal.domain.AccountAllocationIntegrationTest)  Time elapsed: 1.008 sec  &lt;&lt;&lt; ERROR!
  org.springframework.transaction.CannotCreateTransactionException: Could not open JPA EntityManager for transaction; nested exception is javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Cannot open connection
      at org.springframework.orm.jpa.JpaTransactionManager.doBegin(JpaTransactionManager.java:427)
      at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:371)
      at org.springframework.test.context.transaction.TransactionalTestExecutionListener$TransactionContext.startTransaction(TransactionalTestExecutionListener.java:513)
      at org.springframework.test.context.transaction.TransactionalTestExecutionListener.startNewTransaction(TransactionalTestExecutionListener.java:271)
      at org.springframework.test.context.transaction.TransactionalTestExecutionListener.beforeTestMethod(TransactionalTestExecutionListener.java:164)
      at org.springframework.test.context.TestContextManager.beforeTestMethod(TestContextManager.java:358)
      at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:73)
      at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:83)
      at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
      at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)
      at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
      at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
      at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
      at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
      at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
      at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
      at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
      at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
      at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
      at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174)
      at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:53)
      at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:123)
      at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:104)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:601)
      at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:164)
      at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:110)
      at org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:172)
      at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcessWhenForked(SurefireStarter.java:104)
      at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:70)
  Caused by: javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Cannot open connection
      at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1387)
      at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1315)
      at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:1397)
      at org.hibernate.ejb.TransactionImpl.begin(TransactionImpl.java:63)
      at org.springframework.orm.jpa.DefaultJpaDialect.beginTransaction(DefaultJpaDialect.java:70)
      at org.springframework.orm.jpa.JpaTransactionManager.doBegin(JpaTransactionManager.java:377)
      ... 31 more
  Caused by: org.hibernate.exception.GenericJDBCException: Cannot open connection
      at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:140)
      at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:128)
      at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
      at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:52)
      at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:449)
      at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:167)
      at org.hibernate.jdbc.JDBCContext.connection(JDBCContext.java:160)
      at org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:81)
      at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1473)
      at org.hibernate.ejb.TransactionImpl.begin(TransactionImpl.java:60)
      ... 33 more
  Caused by: org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Connection refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.)
      at org.apache.commons.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1549)
      at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1388)
      at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
      at org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider.getConnection(InjectedDataSourceConnectionProvider.java:71)
      at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:446)
      ... 38 more
  </code></pre>
  
  <p>Obviously there's a problem with my login credentials, but I'm not sure what exactly.</p>
  
  <p>My <code>database.properties</code> file:</p>
  
  <pre><code>########################################################
  #                                                      #
  #  This configuration is used for unit-testing only.   #
  #                                                      #
  ########################################################
  
  
  database.driverClassName=org.postgresql.Driver
  database.url=jdbc:postgresql://localhost/test
  database.username=postgres
  database.password=
  </code></pre>
  
  <p>persistence.xml` file:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="no"?&gt;
  &lt;persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"&gt;
      &lt;persistence-unit name="persistenceUnit" transaction-type="RESOURCE_LOCAL"&gt;
  
  
      &lt;provider&gt;org.hibernate.ejb.HibernatePersistence&lt;/provider&gt;
  </code></pre>
  
  <p>
          
          
      </p>
  
  <p><code>ApplicationContext.xml</code> file</p>
  
  <pre><code>    &lt;context:property-placeholder location="classpath*:META-INF/spring/test-database.properties"/&gt;
  
  &lt;bean id="externalProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean"&gt;
     &lt;property name="ignoreResourceNotFound"&gt;&lt;value&gt;true&lt;/value&gt;&lt;/property&gt;
     &lt;property name="locations"&gt;
        &lt;list&gt;
          &lt;value&gt;classpath*:META-INF/conf/configuration.properties&lt;/value&gt;
        &lt;/list&gt;
     &lt;/property&gt;
  &lt;/bean&gt;
  
      &lt;!-- OMITTED FOR THE SAKE OF CLARITY AND SPACE --&gt;
  
       &lt;bean class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" id="dataSource"&gt;
      &lt;property name="driverClassName" value="${database.driverClassName}"/&gt;
      &lt;property name="url" value="${database.url}"/&gt;
      &lt;property name="username" value="${database.username}"/&gt;
      &lt;property name="password" value="${database.password}"/&gt;
      &lt;property name="testOnBorrow" value="true"/&gt;
      &lt;property name="testOnReturn" value="true"/&gt;
      &lt;property name="testWhileIdle" value="false"/&gt;
      &lt;property name="timeBetweenEvictionRunsMillis" value="1800000"/&gt;
      &lt;property name="numTestsPerEvictionRun" value="1"/&gt;
      &lt;property name="maxActive" value="1" /&gt;
      &lt;property name="minEvictableIdleTimeMillis" value="1800000"/&gt;
  &lt;/bean&gt;
  
  &lt;bean class="org.springframework.orm.jpa.JpaTransactionManager" id="transactionManager"&gt;
      &lt;property name="entityManagerFactory" ref="entityManagerFactory"/&gt;
  &lt;/bean&gt;
      &lt;tx:annotation-driven mode="aspectj" transaction-manager="transactionManager"/&gt;
  
      &lt;bean class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" id="entityManagerFactory"&gt;
          &lt;property name="persistenceUnitName" value="persistenceUnit"/&gt;
          &lt;property name="dataSource" ref="dataSource"/&gt;
  
              &lt;property name="persistenceXmlLocation" value="classpath*:META-INF/test-persistence.xml" /&gt;
      &lt;/bean&gt;
  </code></pre>
  
  <p>I'm just starting out with Spring Tool Suite (Spring + Maven + Hibernate) so any help would be greatly welcomed.</p>