1

I want to connect Hibernate with MySQL. I tried all methods, but I'm still getting this error. I'm using Hibernate the version.

avr. 19, 2018 1:55:21 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {5.2.16.Final}
avr. 19, 2018 1:55:21 PM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
avr. 19, 2018 1:55:22 PM org.hibernate.boot.jaxb.internal.stax.LocalXmlResourceResolver resolveEntity
WARN: HHH90000012: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/hibernate-mapping. Use namespace http://www.hibernate.org/dtd/hibernate-mapping instead.  Support for obsolete DTD/XSD namespaces may be removed at any time.
avr. 19, 2018 1:55:24 PM org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
avr. 19, 2018 1:55:24 PM org.hibernate.engine.jdbc.connections.internal.ConnectionProviderInitiator initiateService
WARN: HHH000181: No appropriate connection provider encountered, assuming application will be supplying connections
avr. 19, 2018 1:55:24 PM org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator initiateService
WARN: HHH000342: Could not obtain connection to query metadata : The application must supply JDBC connections
Exception in thread "main" org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:271)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:233)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:210)
    at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:51)
    at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:94)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:242)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:210)
    at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.handleTypes(MetadataBuildingProcess.java:352)
    at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:111)
    at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.build(MetadataBuildingProcess.java:83)
    at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:418)
    at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:87)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:691)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:726)
    at TestHibernate1.main(TestHibernate1.java:14)
Caused by: org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set
    at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.determineDialect(DialectFactoryImpl.java:100)
    at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.buildDialect(DialectFactoryImpl.java:54)
    at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:137)
    at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:35)
    at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:88)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:259)

===========================================================================

=> this is my hibernate.cfg.xml

<?xml version='1.0' encoding='utf-8'?> 
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD//EN"
        "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
  <session-factory>
    <property name="hibernate.dialect">net.sf.hibernate.dialect.MySQLDialect</property>
    <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
    <property name="hibernate.connection.url">jdbc:mysql://localhost/bd_per</property>
    <property name="hibernate.connection.username">root</property>
    <property name="hibernate.connection.password"></property>
    <property name="dialect">net.sf.hibernate.dialect.MySQLDialect</property>
    <property name="show_sql">true</property>
    <mapping resource="Personnes.hbm.xml"/>
  </session-factory>
</hibernate-configuration>

=> this is my hibernate-mapping

<?xml version="1.0"?><!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping"><hibernate-mapping>
  <class name="Personnes" table="personnes">
    <id name="idPersonne" type="int" column="idpersonne">
      <generator class="native"/>
    </id>
    <property name="nomPersonne" type="string" not-null="true" />
    <property name="prenomPersonne" type="string" not-null="true" />


  </class>
</hibernate-mapping>

=> finaly my classe Personnes

public class Personnes {

  private Integer idPersonne;
  private String nomPersonne;
  private String prenomPersonne;


  public Personnes(String nomPersonne, String prenomPersonne) {
    this.nomPersonne = nomPersonne;
    this.prenomPersonne = prenomPersonne;

  }

  public Personnes() {
  }


  public Integer getIdPersonne() {
    return idPersonne;
  }

  public String getNomPersonne() {
    return nomPersonne;
  }

  public String getPrenomPersonne() {
    return prenomPersonne;
  }



  public void setIdPersonne(Integer integer) {
    idPersonne = integer;
  }

 And,thanks for responding as quickly as possible.

  public void setPrenomPersonne(String string) {
    prenomPersonne = string;
  }

public void setNomPersonne(String string) {
    // TODO Auto-generated method stub

}

}
Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
park shin
  • 11
  • 1
  • 2

2 Answers2

0

At least you need to use dialect from this package https://docs.jboss.org/hibernate/orm/3.5/api/org/hibernate/dialect/package-summary.html not from net.sf.hibernate.dialect. For example org.hibernate.dialect.MySQL5Dialect The package you use was in old hibernate version.

And why do you use xml-style definition?

Donz
  • 1,389
  • 1
  • 13
  • 21
  • i use it because Hibernate(ORM) it 's something new for me i had just follow some tutoriels ,i don't know alot about that . what should i do now to solve this problem ? – park shin Apr 19 '18 at 20:12
  • Change dialect to proper. And I think you need something like this tutorial: https://docs.jboss.org/hibernate/orm/3.6/quickstart/en-US/html/hibernate-gsg-tutorial-jpa.html Or, that is better, like this: https://spring.io/guides/gs/accessing-data-jpa/ – Donz Apr 20 '18 at 04:02
0

The proper hibernate dialect needs to be selected depending on the version of MySQL. I faced similar issue and resolution was very simple of using InnoDB dialect version of MySQL. You can refer the proper dialect from package: org.hibernate.dialect

Referece : Link

Hari_pb
  • 7,088
  • 3
  • 45
  • 53
Nikhil
  • 1
  • 1