Began to study Hibernate. I receive the following message:

Mar 25, 2016 6:03:41 PM org.hibernate.Version logVersion INFO: HHH000412: Hibernate Core {5.1.0.Final} Mar 25, 2016 6:03:41 PM org.hibernate.cfg.Environment INFO: HHH000206: hibernate.properties not found Mar 25, 2016 6:03:41 PM org.hibernate.cfg.Environment buildBytecodeProvider INFO: HHH000021: Bytecode provider name: javassist Mar 25, 2016 6:03:41 PM org.hibernate.boot.jaxb. internal.stax.LocalXmlResourceResolver resolveEntity WARN: HHH90000012: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/hibernate-configuration . Use namespace http://www.hibernate.org/dtd/hibernate-configuration instead. Support for obsolete DTD / XSD namespaces may be removed at any time. Mar 25, 2016 6:03:42 PM org.hibernate.annotations.common.reflection.java.JavaReflectionManager INFO: HCANN000001: Hibernate Commons Annotations {5.0.1.Final} Mar 25, 2016 6:03:42 PM org.hibernate .engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure WARN: HHH10001002: Using hibernate built-in connection pool (not for production use!) Mar 25, 2016 6:03:42 PM org.hibernate.engine.jdbc.connections.internal .DriverManagerConnectionProviderImpl buildCreator INFO: HHH10001005: using driver [com.mysql.jdbc.Driver] at URL [jdbc: mysql: // localhost: 3306 / test] Mar 25, 2016 6:03:42 PM org.hibernate.engine.jdbc .connections.internal.DriverManagerConnectionProviderImpl buildCreator INFO: HHH10001001: Connection properties: {user = root, password = ****} Mar 25, 2016 6:03:42 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator INFO: HHH10001003: Autocommit mode: false Mar 25, 2016 6:03:42 PM org.hibernate.engine.jdbc.co nnections.internal.PooledConnections INFO: HHH000115: Hibernate connection pool size: 20 (min = 1) Fri Mar 25 18:03:42 MSK 2016 WARN: Establishment of the connection. According to MySQL 5.5.45+, 5.6.26+, and 5.7.6+ requirements. For compliance with existing applications, it is not SSL to verifyServerCertificate property is set to 'false'. SetSSL = false, or setSSL = true and provide for server certificate verification. Mar 25, 2016 6:03:42 PM org.hibernate.dialect.Dialect INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect Mar 25, 2016 6:03:43 PM org.hibernate.tool.schema.internal .SchemaCreatorImpl applyImportSources INFO: HHH000476: Executing import script 'org.hibernate.tool.schema.internal.exec.ScriptSourceInputNonExistentImpl@4d0f2471'

Hibernate.cfg.xml file

<?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> <!-- a SessionFactory instance listed as /jndi/name --> <session-factory name="java:hibernate/SessionFactory"> <!-- properties --> <property name="connection.driver_class">com.mysql.jdbc.Driver</property> <property name="connection.url">jdbc:mysql://localhost:3306/test</property> <property name="connection.username">root</property> <property name="connection.password">root</property> <property name="dialect">org.hibernate.dialect.MySQLDialect</property> <property name="show_sql">true</property> <property name="hbm2ddl.auto">create</property> <!-- mapping files --> <mapping resource="user.cfg.xml"/> </session-factory> </hibernate-configuration> 

User.cfg.xml file

 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> <hibernate-mapping> <class name="User" table="user"> <id name="id" column="id"><generator class="native"/></id> <property name="firstname" column="first_name" type="string"/> <property name="lasttname" column="last_name" type="string"/> </class> </hibernate-mapping> 
  • It is not clear what the problem is? Heber does not connect to the database or what? All I see in the logs are warnings, but not errors - Alex

1 answer 1

Try the following code in the class where SessionFactory registered:

 import org.hibernate.SessionFactory; import org.hibernate.cfg.Configuration; public class HibernateUtil { private static SessionFactory sessionFactory = null; static { Configuration cfg = new Configuration().configure(); } public static SessionFactory getSessionFactory() { return sessionFactory; } public static void shutdown() { // Close caches and connection pools getSessionFactory().close(); } }