title: Hibernate MySQL Cant create table
body: <p>Im learning hibernate and i got stuck at the very beginning. So the problem is that my app cant auto-create table. Here goes all the code:</p>
  
  <p>hibernate.cfg.xml</p>
  
  <pre><code>&lt;?xml version='1.0' encoding='utf-8'?&gt;
  &lt;!DOCTYPE hibernate-configuration PUBLIC
  "-//Hibernate/Hibernate Configuration DTD//EN"
  "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"&gt;
  
  &lt;hibernate-configuration&gt;
      &lt;session-factory&gt;
          &lt;property name="hibernate.connection.driver_class"&gt;com.mysql.jdbc.Driver&lt;/property&gt;
          &lt;property name="hibernate.connection.url"&gt;jdbc:mysql://localhost:3306/hibernatedb&lt;/property&gt;
          &lt;property name="hibernate.connection.username"&gt;root&lt;/property&gt;
          &lt;property name="hibernate.connection.password"&gt;password&lt;/property&gt;
          &lt;property name="hibernate.connection.pool_size"&gt;1&lt;/property&gt;
          &lt;property name="hibernate.hbm2dll.auto"&gt;create&lt;/property&gt;   
          &lt;property name="hibernate.show_sql"&gt;true&lt;/property&gt;
          &lt;property name="dialect"&gt;org.hibernate.dialect.MySQLDialect&lt;/property&gt;
          &lt;mapping class="azaro.test.hibernate.UserDetails" /&gt;    
      &lt;/session-factory&gt;
  &lt;/hibernate-configuration&gt;
  </code></pre>
  
  <p>HibernateTest.java</p>
  
  <pre><code>package azaro.test.hibernate;
  
  import org.hibernate.Session;
  import org.hibernate.SessionFactory;
  import org.hibernate.cfg.Configuration;
  import org.hibernate.service.ServiceRegistry;
  import org.hibernate.service.ServiceRegistryBuilder;
  
  public class HibernateTest {
  
      public static void main(String[] args) {
          UserDetails user = new UserDetails();
          user.setUserId(1);
          user.setUserName("First User");
  
          Configuration configuration = new Configuration();
          configuration.configure();
          ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry();        
          SessionFactory sessionFactory = configuration.buildSessionFactory(serviceRegistry);
          Session session = sessionFactory.openSession();
          session.beginTransaction();
          session.save(user);
          session.getTransaction().commit();
      }
  
  }
  </code></pre>
  
  <p>UserDetails.java</p>
  
  <pre><code>package azaro.test.hibernate;
  
  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>And the console output:</p>
  
  <pre><code>Hibernate: insert into UserDetails (userName, userId) values (?, ?)
  Sep 23, 2013 6:34:23 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
  WARN: SQL Error: 1146, SQLState: 42S02
  Sep 23, 2013 6:34:23 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
  ERROR: Table 'hibernatedb.userdetails' doesn't exist
  Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not execute statement
      at org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:82)
      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.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:136)
      at org.hibernate.engine.jdbc.batch.internal.NonBatchingBatch.addToBatch(NonBatchingBatch.java:58)
      at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3067)
      at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3509)
      at org.hibernate.action.internal.EntityInsertAction.execute(EntityInsertAction.java:88)
      at org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:377)
      at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:369)
      at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:286)
      at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:339)
      at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:52)
      at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1234)
      at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:404)
      at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.beforeTransactionCommit(JdbcTransaction.java:101)
      at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.commit(AbstractTransactionImpl.java:175)
      at azaro.test.hibernate.HibernateTest.main(HibernateTest.java:23)
  Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'hibernatedb.userdetails' doesn't exist
      at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
      at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
      at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
      at java.lang.reflect.Constructor.newInstance(Unknown Source)
      at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
      at com.mysql.jdbc.Util.getInstance(Util.java:386)
      at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1054)
      at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4190)
      at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4122)
      at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2570)
      at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2731)
      at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2818)
      at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2157)
      at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2460)
      at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2377)
      at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2361)
      at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:133)
      ... 14 more
  </code></pre>
  
  <p>If  you need more info, feel free to ask.</p>