J'essaie de configurer une application d'hibernation simple. Lorsque je l'exécute, la trace de la pile est pleine d'erreurs.
J'ai les dépendances maven suivantes dans mon fichier pom.xml
:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.2.0.Final</version>
</dependency>
<!-- http://mvnrepository.com/artifact/mysql/mysql-connector-Java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-Java</artifactId>
<version>6.0.2</version>
</dependency>
Et la version de MySQL que j'utilise localement est:
5.7.9, for osx10.11 (x86_64)
Je lance, ce qui semble une méthode très simple, et j'obtiens toujours des erreurs:
// create session factory
SessionFactory factory = new Configuration()
.configure("hibernate.cfg.xml")
.addAnnotatedClass(Model.class)
.buildSessionFactory();
// create session
Session session = factory.getCurrentSession();
Model newModel = new Model("....", "...", "...");
// start a transaction
session.beginTransaction();
// save the student object
System.out.println("Saving the model...");
session.save(newModel);
Une fois que ce qui précède est exécuté, je reçois une longue trace de pile ... Le fichier System.out.println n’imprime pas non plus ... La connexion ne semble donc pas se connecter.
INFO: HHH000115: Hibernate connection pool size: 1 (min=1)
Thu Jun 09 17:36:28 EST 2016 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
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:244)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.Java:208)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.Java:189)
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:217)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.Java:189)
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:723)
at com.parkingapi.tests.Test.main(Test.Java:17)
Caused by: org.hibernate.exception.JDBCConnectionException: Error calling Driver#connect
at org.hibernate.engine.jdbc.connections.internal.BasicConnectionCreator$1$1.convert(BasicConnectionCreator.Java:105)
at org.hibernate.engine.jdbc.connections.internal.BasicConnectionCreator.convertSqlException(BasicConnectionCreator.Java:123)
at org.hibernate.engine.jdbc.connections.internal.DriverConnectionCreator.makeConnection(DriverConnectionCreator.Java:41)
at org.hibernate.engine.jdbc.connections.internal.BasicConnectionCreator.createConnection(BasicConnectionCreator.Java:58)
at org.hibernate.engine.jdbc.connections.internal.PooledConnections.addConnections(PooledConnections.Java:106)
at org.hibernate.engine.jdbc.connections.internal.PooledConnections.<init>(PooledConnections.Java:40)
at org.hibernate.engine.jdbc.connections.internal.PooledConnections.<init>(PooledConnections.Java:19)
at org.hibernate.engine.jdbc.connections.internal.PooledConnections$Builder.build(PooledConnections.Java:138)
at org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.buildPool(DriverManagerConnectionProviderImpl.Java:110)
at org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.configure(DriverManagerConnectionProviderImpl.Java:74)
at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.Java:94)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.Java:217)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.Java:189)
at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.buildJdbcConnectionAccess(JdbcEnvironmentInitiator.Java:145)
at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.Java:66)
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:234)
... 14 more
Caused by: Java.sql.SQLException: The server time zone value 'AEST' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.Java:695)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.Java:663)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.Java:653)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.Java:638)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.Java:606)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.Java:624)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.Java:620)
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.Java:68)
at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.Java:1683)
at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.Java:656)
at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.Java:349)
at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.Java:221)
at org.hibernate.engine.jdbc.connections.internal.DriverConnectionCreator.makeConnection(DriverConnectionCreator.Java:38)
... 29 more
Caused by: com.mysql.cj.core.exceptions.InvalidConnectionAttributeException: The server time zone value 'AEST' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.
at Sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at Sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.Java:62)
at Sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.Java:45)
at Java.lang.reflect.Constructor.newInstance(Constructor.Java:408)
at com.mysql.cj.core.exceptions.ExceptionFactory.createException(ExceptionFactory.Java:54)
at com.mysql.cj.core.exceptions.ExceptionFactory.createException(ExceptionFactory.Java:73)
at com.mysql.cj.jdbc.util.TimeUtil.getCanonicalTimezone(TimeUtil.Java:118)
at com.mysql.cj.mysqla.MysqlaSession.configureTimezone(MysqlaSession.Java:308)
at com.mysql.cj.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.Java:2474)
at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.Java:1817)
at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.Java:1673)
... 33 more
Je suis concentré sur cette erreur ici:
La valeur de fuseau horaire du serveur 'AEST' n'est pas reconnue ou représente plus d'un fuseau horaire. Vous devez configurer le serveur ou JDBC pilote (via la propriété de configuration serverTimezone) à utiliser un plus valeur de fuseau horaire spécifique si vous souhaitez utiliser la prise en charge du fuseau horaire.
Je ne sais pas comment je le répare?
L'impression du fuseau horaire (System.out.println (TimeZone.getDefault ());) imprime les détails suivants:
Sun.util.calendar.ZoneInfo [id = "Australie/Melbourne", offset = 36000000, dstSavings = 3600000, useDaylight = true, transitions = 142, lastRule = Java.util.SimpleTimeZone [id = Australie/Melbourne, offset = 36000000, dstSavings = 3600000, useDaylight = true, startYear = 0, startMode = 3, startMonth = 9, startDay = 1, startDayOfWeek = 1, startTime = 7200000, startTimeMode = 1, endMode = 3, endMonth = 3, endDayOfWe 1, heure de fin = 7200000, modeHeure = 1]]
J'ai donc examiné la question qui avait été signalée et essayé de modifier ma chaîne de connexion, mais la trace de la pile est toujours générée. Ci-dessous ma nouvelle URL de connexion. Comme vous pouvez le voir, j'ai changé le serverTimezone en celui de la Timezone.getDefault()
imprimée
jdbc:mysql://localhost:3306/parking_hib?useLegacyDatetimeCode=false;serverTimezone=Australia/Melbourne;useSSL=false;
Il s'avère que 6.x
n'était pas compatible, passer à 5.1.39
l'a corrigé.
essayez d'ajouter ces paramètres ..
jdbc:mysql://localhost:3306/fussa?useLegacyDatetimeCode=false&serverTimezone=UTC
j'utilise mysql-connector-Java 6.0.4
jdbc:mysql://localhost:3306/fussa?useLegacyDatetimeCode=false&serverTimezone=UTC
Utilisez &
au lieu de &
.
Vous pouvez aussi essayer de changer le fuseau horaire sur mysql:
SET GLOBAL time_zone = '00:00';
Et voir le réglage actuel:
SELECT @@global.time_zone, @@session.time_zone;
L'exception est levée car le fuseau horaire du serveur MySql (hérité du fuseau horaire du système) est dans un format différent de celui attendu par le connecteur mysql. Vous devez définir le fuseau horaire MySql sur 'Australie/Sydney'. Regardez cette réponse géniale pour plus de détails: Le fuseau horaire de MySQL doit-il être défini sur UTC?
mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root -p mysql
SET GLOBAL time_zone = 'Australia/Sydney';
Utilisation de default
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/web_student_tracker?user=root&password=&useLegacyDatetimeCode=false&serverTimezone=UTC");
build.gradle>
compile group: 'mysql', name: 'mysql-connector-Java', version: '8.0.11'
application.properties>
spring.datasource.url=jdbc:mysql://localhost:3306/bookworm?useLegacyDatetimeCode=false&serverTimezone=UTC
-
mysql --version
mysql Ver 8.0.11 for osx10.13 on x86_64 (Homebrew)
Cette combinaison fonctionne pour moi.