title: Java - Hibernate connection database
body: <p>I'am learning to use java since few weeks et i want to use Hibernate in simple Java console application.
  I download the last version of Hibernate ORM (4.3.8)</p>
  
  <p>I add this Jars in my ClassPath :</p>
  
  <ul>
  <li>com.mysql.jdbc_5.1.5.jar</li>
  <li>sqlite-jdbc-3.8.7.jar</li>
  <li>Hibernate Library\antlr-2.7.7.jar</li>
  <li>Hibernate Library\dom4j-1.6.1.jar</li>
  <li>Hibernate Library\hibernate-commons-annotations-4.0.5.Final.jar</li>
  <li>Hibernate Library\hibernate-core-4.3.8.Final.jar</li>
  <li>Hibernate Library\hibernate-jpa-2.1-api-1.0.0.Final.jar</li>
  <li>Hibernate Library\jandex-1.1.0.Final.jar</li>
  <li>Hibernate Library\javassist-3.18.1-GA.jar</li>
  <li>Hibernate Library\jboss-logging-3.1.3.GA.jar</li>
  <li>Hibernate Library\jboss-logging-annotations-1.2.0.Beta1.jar</li>
  <li>Hibernate Library\jboss-transaction-api_1.2_spec-1.0.0.Final.jar</li>
  </ul>
  
  <p><strong>My Class :</strong></p>
  
  <pre><code>import javax.persistence.Entity;
  import javax.persistence.Id;
  import javax.persistence.Table;
  
  @Entity
  @Table(name = "STUDENT_INFORMATIONS")
  public class Student_Info {
  
      @Id
      private int rollNo;
  
      private String name;
  
  
      public int getRollNo() {
          return rollNo;
      }
      public void setRollNo(int rollNo) {
          this.rollNo = rollNo;
      }
      public String getName() {
          return name;
      }
      public void setName(String name) {
          this.name = name;
      }
  
  }
  </code></pre>
  
  <p><strong>My Main Code :</strong> </p>
  
  <pre><code>    Student_Info student = new Student_Info();
      student.setName("Fabien");
      student.setRollNo(1);
  
  
      SessionFactory sessionFactory;
      ServiceRegistry serviceRegistry;
  
      Configuration configuration = new Configuration();
      configuration.configure();
  
      serviceRegistry = new StandardServiceRegistryBuilder().applySettings(
              configuration.getProperties()).build();
      sessionFactory = configuration.buildSessionFactory(serviceRegistry);
  
      Session session = sessionFactory.openSession();
      session.beginTransaction();
  
      session.save(student);
  
      session.getTransaction().commit();
      session.close();
      sessionFactory.close();
  </code></pre>
  
  <p><strong>SQLite</strong></p>
  
  <p>First i create an hibernate.cfg.xml configuration for SQLite with dialect property to "util.SQLiteDialect"</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;property name="show_sql"&gt;true&lt;/property&gt;
                  &lt;property name="format_sql"&gt;true&lt;/property&gt;
                  &lt;property name="dialect"&gt;util.SQLiteDialect&lt;/property&gt;
                  &lt;property name="connection.driver_class"&gt;org.sqlite.JDBC&lt;/property&gt;
                  &lt;property name="connection.url"&gt;jdbc:sqlite:SQLiteJDBC.sqlite&lt;/property&gt;
                  &lt;property name="connection.username"&gt;&lt;/property&gt;
                  &lt;property name="connection.password"&gt;&lt;/property&gt;
  
                  &lt;!--  create / update  --&gt;
                  &lt;property name="hibernate.hbm2ddl.auto"&gt;create&lt;/property&gt;
  
                  &lt;!--  Liste des classes à Mapper en base de données --&gt;
                  &lt;!--  &lt;mapping resource="User.hbm.xml"/&gt; --&gt;
                  &lt;mapping class="com.hibernate.Student_Info"/&gt;
          &lt;/session-factory&gt;
  &lt;/hibernate-configuration&gt;
  </code></pre>
  
  <p>When i run my main program i have this error :</p>
  
  <pre><code>...
  INFO: HHH000006: Autocommit mode: false
  janv. 10, 2015 4:23:40 PM org.hibernate.engine.jdbc.connections.internal.DriverM
  anagerConnectionProviderImpl configure
  INFO: HHH000115: Hibernate connection pool size: 20 (min=1)
  Exception in thread "main" org.hibernate.boot.registry.selector.spi.StrategySele
  ctionException: Unable to resolve name [util.SQLiteDialect] as strategy [org.hib
  ernate.dialect.Dialect]
      at org.hibernate.boot.registry.selector.internal.StrategySelectorImpl.selectStr
  ategyImplementor(StrategySelectorImpl.java:128)
      at org.hibernate.boot.registry.selector.internal.StrategySelectorImpl.resolveDe
  faultableStrategy(StrategySelectorImpl.java:155)
      at org.hibernate.boot.registry.selector.internal.StrategySelectorImpl.resolveSt
  rategy(StrategySelectorImpl.java:136)
      at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.constructDiale
  ct(DialectFactoryImpl.java:78)
      at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.buildDialect(D
  ialectFactoryImpl.java:68)
      at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesIm
  pl.java:165)
      at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureSe
  rvice(StandardServiceRegistryImpl.java:111)
      at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService
  (AbstractServiceRegistryImpl.java:234)
      at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(Abstra
  ctServiceRegistryImpl.java:206)
      at org.hibernate.cfg.Configuration.buildTypeRegistrations(Configuration.java:18
  87)
      at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1845)
      at com.hibernate.Main.main(Main.java:26)
  </code></pre>
  
  <p><strong>MySql</strong></p>
  
  <p>After i tried with a mysql Database</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;!DOCTYPE hibernate-configuration SYSTEM 
  "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="hibernate.connection.driver_class"&gt;com.mysql.jdbc.Driver&lt;/property&gt;
          &lt;property name="hibernate.connection.url"&gt;jdbc:mysql://localhost:3306/hierbnate&lt;/property&gt;
          &lt;property name="hibernate.connection.username"&gt;root&lt;/property&gt;
          &lt;property name="hibernate.connection.password"&gt;&lt;/property&gt;
  
          &lt;!--  JDBC Connection pool  --&gt;
          &lt;property name="connection.pool_size"&gt;1&lt;/property&gt;
  
          &lt;!--  SQL Dialect  --&gt;
          &lt;property name="hibernate.dialect"&gt;org.hibernate.dialect.MySQLDialect&lt;/property&gt;
  
          &lt;!--  Disable the second-level cache  --&gt;       
          &lt;property name="cache.provider_cass"&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;!--  create / update  --&gt;
          &lt;property name="hibernate.hbm2ddl.auto"&gt;create&lt;/property&gt;
  
          &lt;!--  Liste des classes Ã  Mapper en base de donnÃ©es --&gt;
          &lt;!--  &lt;mapping resource="User.hbm.xml"/&gt; --&gt;
          &lt;mapping class="com.hibernate.Student_Info"/&gt;
  
      &lt;/session-factory&gt;
  &lt;/hibernate-configuration&gt;
  </code></pre>
  
  <p>When i run my main programm i have this error :</p>
  
  <pre><code>...
  janv. 10, 2015 4:41:43 PM org.hibernate.engine.jdbc.connections.internal.DriverM
  anagerConnectionProviderImpl buildCreator
  INFO: HHH000401: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql://local
  host:3306/hierbnate]
  janv. 10, 2015 4:41:43 PM org.hibernate.engine.jdbc.connections.internal.DriverM
  anagerConnectionProviderImpl buildCreator
  INFO: HHH000046: Connection properties: {user=root, password=****}
  janv. 10, 2015 4:41:43 PM org.hibernate.engine.jdbc.connections.internal.DriverM
  anagerConnectionProviderImpl buildCreator
  INFO: HHH000006: Autocommit mode: false
  janv. 10, 2015 4:41:43 PM org.hibernate.engine.jdbc.connections.internal.DriverM
  anagerConnectionProviderImpl configure
  INFO: HHH000115: Hibernate connection pool size: 1 (min=1)
  Exception in thread "main" org.hibernate.exception.SQLGrammarException: Error ca
  lling Driver#connect
      at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLState
  ConversionDelegate.java:123)
      at org.hibernate.engine.jdbc.connections.internal.BasicConnectionCreator$1$1.co
  nvert(BasicConnectionCreator.java:118)
      at org.hibernate.engine.jdbc.connections.internal.BasicConnectionCreator.conver
  tSqlException(BasicConnectionCreator.java:140)
      at org.hibernate.engine.jdbc.connections.internal.DriverConnectionCreator.makeC
  onnection(DriverConnectionCreator.java:58)
      at org.hibernate.engine.jdbc.connections.internal.BasicConnectionCreator.create
  Connection(BasicConnectionCreator.java:75)
      at org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProvid
  erImpl.configure(DriverManagerConnectionProviderImpl.java:106)
      at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureSe
  rvice(StandardServiceRegistryImpl.java:111)
      at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService
  (AbstractServiceRegistryImpl.java:234)
      at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(Abstra
  ctServiceRegistryImpl.java:206)
      at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.buildJdbcConnectionAcces
  s(JdbcServicesImpl.java:260)
      at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesIm
  pl.java:94)
      at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureSe
  rvice(StandardServiceRegistryImpl.java:111)
      at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService
  (AbstractServiceRegistryImpl.java:234)
      at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(Abstra
  ctServiceRegistryImpl.java:206)
      at org.hibernate.cfg.Configuration.buildTypeRegistrations(Configuration.java:18
  87)
      at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1845)
      at com.hibernate.Main.main(Main.java:25)
  Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown da
  tabase 'hierbnate'
      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:406)
      at com.mysql.jdbc.Util.getInstance(Util.java:381)
      at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1031)
      at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:957)
      at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3376)
      at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3308)
      at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:894)
      at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:3808)
      at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1256)
      at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2032)
      at com.mysql.jdbc.ConnectionImpl.&lt;init&gt;(ConnectionImpl.java:729)
      at com.mysql.jdbc.JDBC4Connection.&lt;init&gt;(JDBC4Connection.java:46)
      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:406)
      at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:302)
      at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:283)
      at org.hibernate.engine.jdbc.connections.internal.DriverConnectionCreator.makeC
  onnection(DriverConnectionCreator.java:55)
      ... 13 more
  </code></pre>
  
  <p>1 - Do you know if is it possible to use hibernate on SQLite ?</p>
  
  <p>2 - If yes, do you know why it doesn't works ?</p>
  
  <p>3 - For MySql, what is the problem ?</p>
  
  <p>thank you very much !!</p>