title: Hibernate does not create the table second time and hangs
body: <p>Hi I am new to Hibernate. I am trying out a sample program,when i execute the code second time hibernate does not create the table and hangs. And when i click on the database table, the database hangs .</p>
  
  <p>I am using postgresql-9.3.3-1 version and hibernate-release-4.3.4.Final.</p>
  
  <p>Following are my code snippets</p>
  
  <p>1.hibernate.cfg.xml</p>
  
  <p>
  </p>
  
  <p></p>
  
  <pre><code>&lt;session-factory&gt;
  
      &lt;property name="connection.driver_class"&gt;org.postgresql.Driver&lt;/property&gt;
      &lt;property name="connection.url"&gt;jdbc:postgresql://localhost:5432/hibernatedb&lt;/property&gt;
      &lt;property name="connection.username"&gt;postgres&lt;/property&gt;
      &lt;property name="connection.password"&gt;postgres&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.PostgreSQL9Dialect&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;!-- Echo all executed SQL to stdout --&gt;
      &lt;property name="show_sql"&gt;true&lt;/property&gt;
      &lt;property name="hbm2ddl.auto"&gt;create&lt;/property&gt;
  
      &lt;mapping class="com.pramati.dto.UserDetails"&gt;&lt;/mapping&gt;
  
  &lt;/session-factory&gt;
  </code></pre>
  
  <p></p>
  
  <p>2.My POJO class. I am using annotations in my pojo class</p>
  
  <p>UserDetails.java</p>
  
  <pre><code>@Entity
  @Table (name="USER_DETAILS")
  public class UserDetails {
  
  @Id
  private int userId;
  private String userName;
  @Temporal (TemporalType.DATE)
  private Date joinDate;
  private String address;
  private String description;
  
  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;
  }
  public Date getJoinDate() {
      return joinDate;
  }
  public void setJoinDate(Date joinDate) {
      this.joinDate = joinDate;
  }
  public String getAddress() {
      return address;
  }
  public void setAddress(String address) {
      this.address = address;
  }
  public String getDescription() {
      return description;
  }
  public void setDescription(String description) {
      this.description = description;
  }
  </code></pre>
  
  <p>}</p>
  
  <ol>
  <li>My Java class with a main method</li>
  </ol>
  
  <p>I am creating a UserDetails Object and retrieving the user name from the newly created UserDetails object. Following is mj java code</p>
  
  <p>public class HibernateTest {</p>
  
  <pre><code>/**
   * @param args
   */
  public static void main(String[] args) {
  
      UserDetails userDetails = new UserDetails();
      userDetails.setUserId(1);
      userDetails.setUserName("Avinash");
      userDetails.setAddress("Rajeev Nagar");
      userDetails.setJoinDate(new Date());
      userDetails.setDescription("Software Engineer");
  
      SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
      Session session = sessionFactory.openSession();
      session.beginTransaction();
      session.save(userDetails);
      session.getTransaction().commit();
      session.close();
  
      userDetails=null;
      session = sessionFactory.openSession();
      session.beginTransaction();
      userDetails = (UserDetails)session.get(UserDetails.class, 1);
      System.out.println("User Name Retrieved is " + userDetails.getUserName());
      session.close();
  }
  </code></pre>
  
  <p>} </p>
  
  <p>For the first time when i run the above java class following is the output displayed in the console of eclipse and it creates UserDetails object</p>
  
  <pre><code>Mar 26, 2014 3:49:06 PM org.hibernate.annotations.common.reflection.java.JavaReflectionManager &lt;clinit&gt;
              INFO: HCANN000001: Hibernate Commons Annotations {4.0.4.Final}
              Mar 26, 2014 3:49:06 PM org.hibernate.Version logVersion
              INFO: HHH000412: Hibernate Core {4.3.4.Final}
              Mar 26, 2014 3:49:06 PM org.hibernate.cfg.Environment &lt;clinit&gt;
              INFO: HHH000206: hibernate.properties not found
              Mar 26, 2014 3:49:06 PM org.hibernate.cfg.Environment buildBytecodeProvider
              INFO: HHH000021: Bytecode provider name : javassist
              Mar 26, 2014 3:49:06 PM org.hibernate.cfg.Configuration configure
              INFO: HHH000043: Configuring from resource: /hibernate.cfg.xml
              Mar 26, 2014 3:49:06 PM org.hibernate.cfg.Configuration getConfigurationInputStream
              INFO: HHH000040: Configuration resource: /hibernate.cfg.xml
              Mar 26, 2014 3:49:06 PM 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!
              Mar 26, 2014 3:49:06 PM org.hibernate.cfg.Configuration doConfigure
              INFO: HHH000041: Configured SessionFactory: null
              Mar 26, 2014 3:49:06 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
              WARN: HHH000402: Using Hibernate built-in connection pool (not for production use!)
              Mar 26, 2014 3:49:06 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
              INFO: HHH000401: using driver [org.postgresql.Driver] at URL [jdbc:postgresql://localhost:5432/hibernatedb]
              Mar 26, 2014 3:49:06 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
              INFO: HHH000046: Connection properties: {user=postgres, password=****}
              Mar 26, 2014 3:49:06 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
              INFO: HHH000006: Autocommit mode: false
              Mar 26, 2014 3:49:06 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
              INFO: HHH000115: Hibernate connection pool size: 1 (min=1)
              Mar 26, 2014 3:49:06 PM org.hibernate.dialect.Dialect &lt;init&gt;
              INFO: HHH000400: Using dialect: org.hibernate.dialect.PostgreSQL9Dialect
              Mar 26, 2014 3:49:06 PM org.hibernate.engine.jdbc.internal.LobCreatorBuilder useContextualLobCreation
              INFO: HHH000424: Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException
              Mar 26, 2014 3:49:06 PM org.hibernate.engine.transaction.internal.TransactionFactoryInitiator initiateService
              INFO: HHH000399: Using default transaction strategy (direct JDBC transactions)
              Mar 26, 2014 3:49:06 PM org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory &lt;init&gt;
              INFO: HHH000397: Using ASTQueryTranslatorFactory
              Mar 26, 2014 3:49:07 PM org.hibernate.tool.hbm2ddl.SchemaExport execute
              INFO: HHH000227: Running hbm2ddl schema export
              Hibernate: drop table USER_DETAILS cascade
              Hibernate: create table USER_DETAILS (userId int4 not null, address varchar(255), description varchar(255), joinDate date, userName varchar(255), primary key (userId))
              Mar 26, 2014 3:49:07 PM org.hibernate.tool.hbm2ddl.SchemaExport execute
              INFO: HHH000230: Schema export complete
              Hibernate: insert into USER_DETAILS (address, description, joinDate, userName, userId) values (?, ?, ?, ?, ?)
              Hibernate: select userdetail0_.userId as userId1_0_0_, userdetail0_.address as address2_0_0_, userdetail0_.description as descript3_0_0_, userdetail0_.joinDate as joinDate4_0_0_, userdetail0_.userName as userName5_0_0_ from USER_DETAILS userdetail0_ where userdetail0_.userId=?
              User Name Retrieved is Avinash
  </code></pre>
  
  <p>The second time i run the above code, hibernate does not create the table. Following is the output of the second run</p>
  
  <pre><code>    Mar 26, 2014 3:50:52 PM org.hibernate.annotations.common.reflection.java.JavaReflectionManager &lt;clinit&gt;
      INFO: HCANN000001: Hibernate Commons Annotations {4.0.4.Final}
      Mar 26, 2014 3:50:52 PM org.hibernate.Version logVersion
      INFO: HHH000412: Hibernate Core {4.3.4.Final}
      Mar 26, 2014 3:50:52 PM org.hibernate.cfg.Environment &lt;clinit&gt;
      INFO: HHH000206: hibernate.properties not found
      Mar 26, 2014 3:50:52 PM org.hibernate.cfg.Environment buildBytecodeProvider
      INFO: HHH000021: Bytecode provider name : javassist
      Mar 26, 2014 3:50:52 PM org.hibernate.cfg.Configuration configure
      INFO: HHH000043: Configuring from resource: /hibernate.cfg.xml
      Mar 26, 2014 3:50:52 PM org.hibernate.cfg.Configuration getConfigurationInputStream
      INFO: HHH000040: Configuration resource: /hibernate.cfg.xml
      Mar 26, 2014 3:50:52 PM 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!
      Mar 26, 2014 3:50:52 PM org.hibernate.cfg.Configuration doConfigure
      INFO: HHH000041: Configured SessionFactory: null
      Mar 26, 2014 3:50:52 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
      WARN: HHH000402: Using Hibernate built-in connection pool (not for production use!)
      Mar 26, 2014 3:50:52 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
      INFO: HHH000401: using driver [org.postgresql.Driver] at URL [jdbc:postgresql://localhost:5432/hibernatedb]
      Mar 26, 2014 3:50:52 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
      INFO: HHH000046: Connection properties: {user=postgres, password=****}
      Mar 26, 2014 3:50:52 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
      INFO: HHH000006: Autocommit mode: false
      Mar 26, 2014 3:50:52 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
      INFO: HHH000115: Hibernate connection pool size: 1 (min=1)
      Mar 26, 2014 3:50:52 PM org.hibernate.dialect.Dialect &lt;init&gt;
      INFO: HHH000400: Using dialect: org.hibernate.dialect.PostgreSQL9Dialect
      Mar 26, 2014 3:50:52 PM org.hibernate.engine.jdbc.internal.LobCreatorBuilder useContextualLobCreation
      INFO: HHH000424: Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException
      Mar 26, 2014 3:50:52 PM org.hibernate.engine.transaction.internal.TransactionFactoryInitiator initiateService
      INFO: HHH000399: Using default transaction strategy (direct JDBC transactions)
      Mar 26, 2014 3:50:52 PM org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory &lt;init&gt;
      INFO: HHH000397: Using ASTQueryTranslatorFactory
      Mar 26, 2014 3:50:52 PM org.hibernate.tool.hbm2ddl.SchemaExport execute
      INFO: HHH000227: Running hbm2ddl schema export
      Hibernate: drop table USER_DETAILS cascade
  </code></pre>
  
  <p>It gets stuck after the line saying "drop table USER_DETAILS cascade"
  Please do suggest or help me with the problem. Thanks in Advance</p>