title: Unable to create a table using Hibernate and MYSQL
body: <p>I am new to hibernate and I have to get some strange behavior from it, below is the scenario.</p>
  
  <p>My java files are,</p>
  
  <p>UserDetails.java :-</p>
  
  <pre><code>package org.mahesh.test;
  import javax.persistence.Entity;
  import javax.persistence.Id;
  @Entity
  public class UserDetails {
  @Id
  private int userId;
  private String userName;
  public String getUserName() {
      return userName;
  }
  public void setUserName(String userName) {
      this.userName = userName;
  }
  public int getUserId() {
      return userId;
  }
  public void setUserId(int userId) {
      this.userId = userId;
  }   
  }
  </code></pre>
  
  <p>HibernateTest.java is,</p>
  
  <pre><code> package org.mahesh.hibernate;
   import org.hibernate.Session;
   import org.hibernate.SessionFactory;
   import org.hibernate.cfg.Configuration;
   import org.mahesh.securifi.UserDetails;
   public class HibernateTest {
  
   public static void main(String[] args) {
      // TODO Auto-generated method stub
      UserDetails user = new UserDetails();
      user.setUserId(1);
      user.setUserName("Mahesh");
  
      SessionFactory sessionFactory = new   Configuration().configure().buildSessionFactory();
      Session session = sessionFactory.openSession();
      session.beginTransaction();
      session.save(user);
      session.getTransaction().commit();
    }
    }
  </code></pre>
  
  <p>hibernate.cfg.xml is,</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://www.hibernate.org/dtd/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;com.mysql.jdbc.Driver&lt;/property&gt;
      &lt;property name="connection.url"&gt;jdbc:mysql://localhost:3306/employee&lt;/property&gt;
      &lt;property name="connection.username"&gt;root&lt;/property&gt;
      &lt;property name="connection.password"&gt;root&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.MySQLDialect&lt;/property&gt;
  
      &lt;!-- Disable the second-level cache  --&gt;
      &lt;property name="cache.provider_class"&gt;org.hibernate.cache.internal.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="hibernate.hbm2ddl.auto"&gt;create&lt;/property&gt;
  
      &lt;!-- Names the annotated entity class --&gt;
      &lt;mapping class="org.mahesh.securifi.UserDetails"/&gt;
  
  &lt;/session-factory&gt;
  
  &lt;/hibernate-configuration&gt;
  </code></pre>
  
  <p>Full stack trace is,</p>
  
  <pre><code>Mar 24, 2017 10:28:20 AM org.hibernate.Version logVersion
  INFO: HHH000412: Hibernate Core {5.2.9.Final}
  Mar 24, 2017 10:28:20 AM org.hibernate.cfg.Environment &lt;clinit&gt;
  INFO: HHH000206: hibernate.properties not found
  Mar 24, 2017 10:28:20 AM         org.hibernate.annotations.common.reflection.java.JavaReflectionManager &lt;clinit&gt;
  INFO: HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
  Mar 24, 2017 10:28:20 AM     org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderIm    pl configure
  WARN: HHH10001002: Using Hibernate built-in connection pool (not for     production use!)
  Mar 24, 2017 10:28:20 AM     org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderIm    pl buildCreator
  INFO: HHH10001005: using driver [com.mysql.jdbc.Driver] at URL     [jdbc:mysql://localhost:3306/employee]
  Mar 24, 2017 10:28:20 AM     org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderIm    pl buildCreator
  INFO: HHH10001001: Connection properties: {user=root, password=****}
  Mar 24, 2017 10:28:20 AM     org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderIm    pl buildCreator
  INFO: HHH10001003: Autocommit mode: false
  Mar 24, 2017 10:28:20 AM     org.hibernate.engine.jdbc.connections.internal.PooledConnections &lt;init&gt;
  INFO: HHH000115: Hibernate connection pool size: 1 (min=1)
  Mar 24, 2017 10:28:20 AM org.hibernate.dialect.Dialect &lt;init&gt;
  INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect
  Mar 24, 2017 10:28:20 AM     org.hibernate.engine.jdbc.env.internal.LobCreatorBuilderImpl     useContextualLobCreation
  INFO: HHH000423: Disabling contextual LOB creation as JDBC driver reported     JDBC version [3] less than 4
  Hibernate: drop table if exists UserDetails
  Mar 24, 2017 10:28:21 AM     org.hibernate.resource.transaction.backend.jdbc.internal.DdlTransactionIsolatorN    onJtaImpl getIsolatedConnection
  INFO: HHH10001501: Connection obtained from JdbcConnectionAccess     [org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator$ConnectionProvi    derJdbcConnectionAccess@40db2a24] for (non-JTA) DDL execution was not in auto-commit mode; the Connection 'local transaction' will be committed and the Connection will be set into auto-commit mode.
  Hibernate: create table UserDetails (userId integer not null, userName     varchar(255), primary key (userId)) type=MyISAM
  Mar 24, 2017 10:28:21 AM     org.hibernate.resource.transaction.backend.jdbc.internal.DdlTransactionIsolatorN    onJtaImpl getIsolatedConnection
  INFO: HHH10001501: Connection obtained from JdbcConnectionAccess     [org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator$ConnectionProviderJdbcConnectionAccess@22356acd] for (non-JTA) DDL execution was not in auto-commit mode; the Connection 'local transaction' will be committed and the Connection will be set into auto-commit mode.
  Mar 24, 2017 10:28:21 AM     org.hibernate.tool.schema.internal.ExceptionHandlerLoggedImpl handleException
  WARN: GenerationTarget encountered exception accepting command : Error     executing DDL via JDBC Statement
  org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL via JDBC Statement
  at     org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:67)
  at     org.hibernate.tool.schema.internal.SchemaCreatorImpl.applySqlString(SchemaCreato    rImpl.java:440)
  at     org.hibernate.tool.schema.internal.SchemaCreatorImpl.applySqlStrings(SchemaCreat    orImpl.java:424)
  at         org.hibernate.tool.schema.internal.SchemaCreatorImpl.createFromMetadata(SchemaCr    eatorImpl.java:315)
  at     org.hibernate.tool.schema.internal.SchemaCreatorImpl.performCreation(SchemaCreat    orImpl.java:166)
  at     org.hibernate.tool.schema.internal.SchemaCreatorImpl.doCreation(SchemaCreatorImp    l.java:135)
  at     org.hibernate.tool.schema.internal.SchemaCreatorImpl.doCreation(SchemaCreatorImp    l.java:121)
  at     org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.performDatabaseAct    ion(SchemaManagementToolCoordinator.java:155)
  at     org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.process(SchemaMana    gementToolCoordinator.java:72)
  at org.hibernate.internal.SessionFactoryImpl.&lt;init&gt;    (SessionFactoryImpl.java:309)
  at     org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilde    rImpl.java:445)
  at     org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:710)
  at     org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:726)
  at org.mahesh.hibernate.HibernateTest.main(HibernateTest.java:16)
  Caused by: com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: You have an         error in your SQL syntax; check the manual that corresponds to your MySQL server     version for the right syntax to use near 'type=MyISAM' at line 1
      at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:936)
      at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2985)
      at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1631)
      at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1723)
      at com.mysql.jdbc.Connection.execSQL(Connection.java:3277)
      at com.mysql.jdbc.Connection.execSQL(Connection.java:3206)
      at com.mysql.jdbc.Statement.execute(Statement.java:727)
      at     org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(Genera    tionTargetToDatabase.java:54)
  ... 13 more
  
  Mar 24, 2017 10:28:21 AM     org.hibernate.tool.schema.internal.SchemaCreatorImpl applyImportSources
  INFO: HHH000476: Executing import script     'org.hibernate.tool.schema.internal.exec.ScriptSourceInputNonExistentImpl@6e4566    f1'
  Hibernate: insert into UserDetails (userName, userId) values (?, ?)
  Mar 24, 2017 10:28:21 AM org.hibernate.engine.jdbc.spi.SqlExceptionHelper         logExceptions
  WARN: SQL Error: 1146, SQLState: 42S02
  Mar 24, 2017 10:28:21 AM org.hibernate.engine.jdbc.spi.SqlExceptionHelper     logExceptions
  ERROR: Table 'employee.userdetails' doesn't exist
  Mar 24, 2017 10:28:21 AM     org.hibernate.engine.jdbc.batch.internal.AbstractBatchImpl release
  INFO: HHH000010: On release of batch it still contained JDBC statements
  Mar 24, 2017 10:28:21 AM org.hibernate.internal.ExceptionMapperStandardImpl     mapManagedFlushFailure
  ERROR: HHH000346: Error during managed flush     [org.hibernate.exception.SQLGrammarException: could not execute statement]
  Exception in thread "main" javax.persistence.PersistenceException:     org.hibernate.exception.SQLGrammarException: could not execute statement
      at     org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.jav    a:147)
  at     org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.jav    a:155)
  at     org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.jav    a:162)
  at org.hibernate.internal.SessionImpl.doFlush(SessionImpl.java:1434)
  at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:484)
  at     org.hibernate.internal.SessionImpl.flushBeforeTransactionCompletion(SessionImpl.    java:3190)
  at     org.hibernate.internal.SessionImpl.beforeTransactionCompletion(SessionImpl.java:    2404)
  at     org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl.beforeTransactionCompleti    on(JdbcCoordinatorImpl.java:467)
  at     org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransa        ctionCoordinatorImpl.beforeCompletionCallback(JdbcResourceLocalTransactionCoordi    natorImpl.java:146)
  at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransa        ctionCoordinatorImpl.access$100(JdbcResourceLocalTransactionCoordinatorImpl.java    :38)
  at     org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransa    ctionCoordinatorImpl$TransactionDriverControlImpl.commit(JdbcResourceLocalTransa    ctionCoordinatorImpl.java:220)
  at org.hibernate.engine.transaction.internal.TransactionImpl.commit(TransactionImpl    .java:68)
  at org.mahesh.hibernate.HibernateTest.main(HibernateTest.java:20)
  Caused by: org.hibernate.exception.SQLGrammarException: could not execute statement
  at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:106)
  at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:42)
  at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:111)
  at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:97)
  at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:208)
  at org.hibernate.engine.jdbc.batch.internal.NonBatchingBatch.addToBatch(NonBatchingBatch.java:45)
  at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3003)
  at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3503)
  at org.hibernate.action.internal.EntityInsertAction.execute(EntityInsertAction.java:89)
  at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:586)
  at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:460)
  at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:337)
  at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:39)
  at org.hibernate.internal.SessionImpl.doFlush(SessionImpl.java:1428)
  ... 9 more
  Caused by: com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: Table     'employee.userdetails' doesn't exist
  at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:936)
  at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2985)
  at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1631)
  at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1723)
  at com.mysql.jdbc.Connection.execSQL(Connection.java:3283)
  at         com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1332)
  at     com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1604)
  at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1519)
  at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1504)
  at     org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetRe    turnImpl.java:205)
  ... 18 more
  </code></pre>
  
  <p>Getting this error while running.</p>