title: Error while connecting to DB with hibernate
body: <p>I am trying to learn Hibernate. And this is my first program, however I cannot figure the problem out while compiling. I use Postgresql, which is already opened to the connection.</p>
  
  <p>This is the model:</p>
  
  <pre><code>package org.javabrains.koushik.dto;
  
  import javax.persistence.Entity;
  import javax.persistence.Id;
  
  @Entity
  
  public class UserDetails {
      @Id
      private int userId;
      private String userName;
  
      public int getUserId() {
          return userId;
      }
      public void setUserId(int userId) {
          this.userId = userId;
      }
      public String getUserName() {
          return userName;
      }
      public void setUserName(String userName) {
          this.userName = userName;
      }
  }
  </code></pre>
  
  <p>Test class:</p>
  
  <pre><code>package org.koushik.hibernate;
  
  import org.hibernate.Session;
  import org.hibernate.SessionFactory;
  import org.hibernate.cfg.Configuration;
  import org.javabrains.koushik.dto.UserDetails;
  
  public class HibernateTest {
  
      /**
       * @param args
       */
      public static void main(String[] args) {
          UserDetails user = new UserDetails();
          user.setUserId(1);
          user.setUserName("First User");
  
          @SuppressWarnings("deprecation")
          SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
          Session session = sessionFactory.openSession();
          session.beginTransaction();
          session.save(user);
          session.getTransaction().commit();
  
      }
  
  }
  </code></pre>
  
  <p>And the hibernate.cfg.xml:</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://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"&gt;
  
  &lt;hibernate-configuration&gt;
  
      &lt;session-factory&gt;
  
          &lt;!-- Database connection settings --&gt;
          &lt;property name="connection.driver_class"&gt;org.postgresql.Driver&lt;/property&gt;
          &lt;property name="connection.url"&gt;jdbc:postgresql://host:5432/hibernatedb&lt;/property&gt;
          &lt;property name="connection.username"&gt;postgres&lt;/property&gt;
          &lt;property name="connection.password"&gt;06640265&lt;/property&gt;
  
          &lt;!-- JDBC connection pool (use the built-in) --&gt;
          &lt;property name="connection.pool_size"&gt;1&lt;/property&gt;
  
          &lt;!-- SQL dialect --&gt;
          &lt;property name="dialect"&gt;org.hibernate.dialect.PostgreSQLDialect&lt;/property&gt;
  
          &lt;!-- Enable Hibernate's automatic session context management --&gt;
          &lt;property name="current_session_context_class"&gt;thread&lt;/property&gt;
  
          &lt;!-- Disable the second-level cache  --&gt;
          &lt;property name="cache.provider_class"&gt;org.hibernate.cache.NoCacheProvider&lt;/property&gt;
  
          &lt;!-- Echo all executed SQL to stdout --&gt;
          &lt;property name="show_sql"&gt;true&lt;/property&gt;
  
          &lt;!-- Drop and re-create the database schema on startup --&gt;
          &lt;property name="hbm2ddl.auto"&gt;update&lt;/property&gt;
  
          &lt;mapping class="org.javabrains.koushik.dto.UserDetails"/&gt;
  
      &lt;/session-factory&gt;
  
  &lt;/hibernate-configuration&gt;
  </code></pre>
  
  <p>And the log:</p>
  
  <pre><code>Tem 06, 2013 12:02:47 AM org.hibernate.annotations.common.Version &lt;clinit&gt;
  INFO: HCANN000001: Hibernate Commons Annotations {4.0.2.Final}
  Tem 06, 2013 12:02:47 AM org.hibernate.Version logVersion
  INFO: HHH000412: Hibernate Core {4.2.3.Final}
  Tem 06, 2013 12:02:47 AM org.hibernate.cfg.Environment &lt;clinit&gt;
  INFO: HHH000206: hibernate.properties not found
  Tem 06, 2013 12:02:47 AM org.hibernate.cfg.Environment buildBytecodeProvider
  INFO: HHH000021: Bytecode provider name : javassist
  Tem 06, 2013 12:02:47 AM org.hibernate.cfg.Configuration configure
  INFO: HHH000043: Configuring from resource: /hibernate.cfg.xml
  Tem 06, 2013 12:02:47 AM org.hibernate.cfg.Configuration getConfigurationInputStream
  INFO: HHH000040: Configuration resource: /hibernate.cfg.xml
  Tem 06, 2013 12:02:47 AM org.hibernate.internal.util.xml.DTDEntityResolver resolveEntity
  WARN: HHH000223: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!
  Tem 06, 2013 12:02:48 AM org.hibernate.cfg.Configuration doConfigure
  INFO: HHH000041: Configured SessionFactory: null
  Tem 06, 2013 12:02:48 AM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
  INFO: HHH000402: Using Hibernate built-in connection pool (not for production use!)
  Tem 06, 2013 12:02:48 AM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
  INFO: HHH000115: Hibernate connection pool size: 1
  Tem 06, 2013 12:02:48 AM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
  INFO: HHH000006: Autocommit mode: false
  Tem 06, 2013 12:02:48 AM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
  INFO: HHH000401: using driver [org.postgresql.Driver] at URL [jdbc:postgresql://host:5432/hibernatedb]
  Tem 06, 2013 12:02:48 AM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
  INFO: HHH000046: Connection properties: {user=postgres, password=****}
  Tem 06, 2013 12:02:50 AM org.hibernate.engine.jdbc.internal.JdbcServicesImpl configure
  WARN: HHH000342: Could not obtain connection to query metadata : Bağlantı denemesi başarısız oldu.
  Tem 06, 2013 12:02:50 AM org.hibernate.dialect.Dialect &lt;init&gt;
  INFO: HHH000400: Using dialect: org.hibernate.dialect.PostgreSQLDialect
  Tem 06, 2013 12:02:50 AM org.hibernate.engine.jdbc.internal.LobCreatorBuilder useContextualLobCreation
  INFO: HHH000422: Disabling contextual LOB creation as connection was null
  Tem 06, 2013 12:02:50 AM org.hibernate.engine.transaction.internal.TransactionFactoryInitiator initiateService
  INFO: HHH000399: Using default transaction strategy (direct JDBC transactions)
  Tem 06, 2013 12:02:50 AM org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory &lt;init&gt;
  INFO: HHH000397: Using ASTQueryTranslatorFactory
  Tem 06, 2013 12:02:50 AM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
  INFO: HHH000228: Running hbm2ddl schema update
  Tem 06, 2013 12:02:50 AM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
  INFO: HHH000102: Fetching database metadata
  Tem 06, 2013 12:02:50 AM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
  ERROR: HHH000319: Could not get database metadata
  org.postgresql.util.PSQLException: Bağlantı denemesi başarısız oldu.
      at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:225)
      at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:64)
      at org.postgresql.jdbc2.AbstractJdbc2Connection.&lt;init&gt;(AbstractJdbc2Connection.java:136)
      at org.postgresql.jdbc3.AbstractJdbc3Connection.&lt;init&gt;(AbstractJdbc3Connection.java:29)
      at org.postgresql.jdbc3g.AbstractJdbc3gConnection.&lt;init&gt;(AbstractJdbc3gConnection.java:21)
      at org.postgresql.jdbc4.AbstractJdbc4Connection.&lt;init&gt;(AbstractJdbc4Connection.java:31)
      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.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl.getConnection(DriverManagerConnectionProviderImpl.java:204)
      at org.hibernate.tool.hbm2ddl.SuppliedConnectionProviderConnectionHelper.prepare(SuppliedConnectionProviderConnectionHelper.java:51)
      at org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:194)
      at org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:178)
      at org.hibernate.internal.SessionFactoryImpl.&lt;init&gt;(SessionFactoryImpl.java:505)
      at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1769)
      at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1840)
      at org.koushik.hibernate.HibernateTest.main(HibernateTest.java:19)
  Caused by: java.net.UnknownHostException: host
      at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
      at java.net.PlainSocketImpl.connect(Unknown Source)
      at java.net.SocksSocketImpl.connect(Unknown Source)
      at java.net.Socket.connect(Unknown Source)
      at java.net.Socket.connect(Unknown Source)
      at org.postgresql.core.PGStream.&lt;init&gt;(PGStream.java:60)
      at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:101)
      ... 16 more
  
  Tem 06, 2013 12:02:50 AM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
  ERROR: HHH000299: Could not complete schema update
  org.postgresql.util.PSQLException: Bağlantı denemesi başarısız oldu.
      at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:225)
      at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:64)
      at org.postgresql.jdbc2.AbstractJdbc2Connection.&lt;init&gt;(AbstractJdbc2Connection.java:136)
      at org.postgresql.jdbc3.AbstractJdbc3Connection.&lt;init&gt;(AbstractJdbc3Connection.java:29)
      at org.postgresql.jdbc3g.AbstractJdbc3gConnection.&lt;init&gt;(AbstractJdbc3gConnection.java:21)
      at org.postgresql.jdbc4.AbstractJdbc4Connection.&lt;init&gt;(AbstractJdbc4Connection.java:31)
      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.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl.getConnection(DriverManagerConnectionProviderImpl.java:204)
      at org.hibernate.tool.hbm2ddl.SuppliedConnectionProviderConnectionHelper.prepare(SuppliedConnectionProviderConnectionHelper.java:51)
      at org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:194)
      at org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:178)
      at org.hibernate.internal.SessionFactoryImpl.&lt;init&gt;(SessionFactoryImpl.java:505)
      at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1769)
      at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1840)
      at org.koushik.hibernate.HibernateTest.main(HibernateTest.java:19)
  Caused by: java.net.UnknownHostException: host
      at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
      at java.net.PlainSocketImpl.connect(Unknown Source)
      at java.net.SocksSocketImpl.connect(Unknown Source)
      at java.net.Socket.connect(Unknown Source)
      at java.net.Socket.connect(Unknown Source)
      at org.postgresql.core.PGStream.&lt;init&gt;(PGStream.java:60)
      at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:101)
      ... 16 more
  
  Tem 06, 2013 12:02:51 AM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
  WARN: SQL Error: 0, SQLState: 08001
  Tem 06, 2013 12:02:51 AM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
  ERROR: Bağlantı denemesi başarısız oldu.
  Exception in thread "main" org.hibernate.exception.JDBCConnectionException: Could not open connection
      at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:132)
      at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49)
      at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125)
      at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:110)
      at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.obtainConnection(LogicalConnectionImpl.java:221)
      at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.getConnection(LogicalConnectionImpl.java:157)
      at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.doBegin(JdbcTransaction.java:67)
      at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.begin(AbstractTransactionImpl.java:160)
      at org.hibernate.internal.SessionImpl.beginTransaction(SessionImpl.java:1426)
      at org.koushik.hibernate.HibernateTest.main(HibernateTest.java:21)
  Caused by: org.postgresql.util.PSQLException: Bağlantı denemesi başarısız oldu.
      at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:225)
      at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:64)
      at org.postgresql.jdbc2.AbstractJdbc2Connection.&lt;init&gt;(AbstractJdbc2Connection.java:136)
      at org.postgresql.jdbc3.AbstractJdbc3Connection.&lt;init&gt;(AbstractJdbc3Connection.java:29)
      at org.postgresql.jdbc3g.AbstractJdbc3gConnection.&lt;init&gt;(AbstractJdbc3gConnection.java:21)
      at org.postgresql.jdbc4.AbstractJdbc4Connection.&lt;init&gt;(AbstractJdbc4Connection.java:31)
      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.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl.getConnection(DriverManagerConnectionProviderImpl.java:204)
      at org.hibernate.internal.AbstractSessionImpl$NonContextualJdbcConnectionAccess.obtainConnection(AbstractSessionImpl.java:292)
      at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.obtainConnection(LogicalConnectionImpl.java:214)
      ... 5 more
  Caused by: java.net.UnknownHostException: host
      at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
      at java.net.PlainSocketImpl.connect(Unknown Source)
      at java.net.SocksSocketImpl.connect(Unknown Source)
      at java.net.Socket.connect(Unknown Source)
      at java.net.Socket.connect(Unknown Source)
      at org.postgresql.core.PGStream.&lt;init&gt;(PGStream.java:60)
      at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:101)
      ... 16 more
  </code></pre>
  
  <p>I think the problem is hilarious, sorry for that but it is just starting point for me.</p>