From be7cc76556f1a2efd715b24ba4516fba0ddbbec1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yoann=20Rodi=C3=A8re?= Date: Mon, 26 Aug 2019 13:53:29 +0200 Subject: [PATCH] HHH-13582 Upgrade MySQL Connector/J to 8.0.17 ConnectorJ 8 is the version used in WildFly integration tests. ConnectorJ 5 is apparently no longer tested. Note this solves most timezone-related issues we've been having. --- gradle/libraries.gradle | 3 +-- .../hibernate/test/annotations/EntityTest.java | 6 ++---- .../autocommit/MySQLSkipAutoCommitTest.java | 17 +++++++++++++---- .../test/temporal/TimePropertyTest.java | 7 ++++++- .../databases/mysql56/matrix.gradle | 2 +- .../databases/mysql8/matrix.gradle | 2 +- 6 files changed, 24 insertions(+), 13 deletions(-) diff --git a/gradle/libraries.gradle b/gradle/libraries.gradle index 98fa8af98c..16d24e151b 100644 --- a/gradle/libraries.gradle +++ b/gradle/libraries.gradle @@ -109,8 +109,7 @@ ext { hsqldb: "org.hsqldb:hsqldb:2.3.2", derby: "org.apache.derby:derby:10.11.1.1", postgresql: 'org.postgresql:postgresql:42.2.2', - //Upgrade MySQL Driver only when this issue gets fixed: https://bugs.mysql.com/bug.php?id=85941 - mysql: 'mysql:mysql-connector-java:5.1.46', + mysql: 'mysql:mysql-connector-java:8.0.17', mariadb: 'org.mariadb.jdbc:mariadb-java-client:2.2.3', oracle: 'com.oracle.jdbc:ojdbc8:12.2.0.1', diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/EntityTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/EntityTest.java index afaf60ebd8..5dd684f870 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/EntityTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/EntityTest.java @@ -24,9 +24,7 @@ import org.hibernate.boot.MetadataBuilder; import org.hibernate.boot.model.naming.ImplicitNamingStrategyJpaCompliantImpl; import org.hibernate.dialect.Dialect; -import org.hibernate.dialect.MySQL57Dialect; -import org.hibernate.dialect.MySQL8Dialect; -import org.hibernate.dialect.MySQLDialect; +import org.hibernate.dialect.MySQL5Dialect; import org.hibernate.dialect.Oracle10gDialect; import org.hibernate.query.Query; import org.hibernate.tool.hbm2ddl.SchemaExport; @@ -373,7 +371,7 @@ public void testNonGetter() throws Exception { @SkipForDialect(value = Oracle10gDialect.class, comment = "oracle12c returns time in getDate. For now, skip.") public void testTemporalType() throws Exception { - final ZoneId zoneId = ( Dialect.getDialect() instanceof MySQL8Dialect ) ? ZoneId.of( "UTC") + final ZoneId zoneId = ( Dialect.getDialect() instanceof MySQL5Dialect ) ? ZoneId.of( "UTC") : ZoneId.systemDefault(); Flight airFrance = doInHibernate( this::sessionFactory, session -> { diff --git a/hibernate-core/src/test/java/org/hibernate/test/resource/transaction/jdbc/autocommit/MySQLSkipAutoCommitTest.java b/hibernate-core/src/test/java/org/hibernate/test/resource/transaction/jdbc/autocommit/MySQLSkipAutoCommitTest.java index b8f61a87f7..a417dc99fb 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/resource/transaction/jdbc/autocommit/MySQLSkipAutoCommitTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/resource/transaction/jdbc/autocommit/MySQLSkipAutoCommitTest.java @@ -30,11 +30,20 @@ protected DataSource dataSource() { if ( getDialect() instanceof MariaDBDialect ) { dataSource = ReflectionUtil.newInstance( "org.mariadb.jdbc.MariaDbDataSource" ); } - else if ( getDialect() instanceof MySQL8Dialect ) { - dataSource = ReflectionUtil.newInstance( "com.mysql.cj.jdbc.MysqlDataSource" ); - } else if ( getDialect() instanceof MySQLDialect ) { - dataSource = ReflectionUtil.newInstance( "com.mysql.jdbc.jdbc2.optional.MysqlDataSource" ); + try { + // ConnectorJ 8 + dataSource = ReflectionUtil.newInstance( "com.mysql.cj.jdbc.MysqlDataSource" ); + } + catch (IllegalArgumentException e) { + try { + // ConnectorJ 5 + dataSource = ReflectionUtil.newInstance( "com.mysql.jdbc.jdbc2.optional.MysqlDataSource" ); + } catch (Exception e2) { + e2.addSuppressed( e ); + throw e; + } + } } ReflectionUtil.setProperty( dataSource, "url", Environment.getProperties().getProperty( AvailableSettings.URL ) ); ReflectionUtil.setProperty( dataSource, "user", Environment.getProperties().getProperty( AvailableSettings.USER ) ); diff --git a/hibernate-core/src/test/java/org/hibernate/test/temporal/TimePropertyTest.java b/hibernate-core/src/test/java/org/hibernate/test/temporal/TimePropertyTest.java index 935d011c14..d77d122861 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/temporal/TimePropertyTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/temporal/TimePropertyTest.java @@ -9,6 +9,7 @@ import java.sql.Time; import java.text.DateFormat; import java.text.SimpleDateFormat; +import java.util.Calendar; import java.util.Date; import javax.persistence.GeneratedValue; import javax.persistence.Id; @@ -36,7 +37,11 @@ public class TimePropertyTest extends BaseCoreFunctionalTestCase { @Test public void testTimeAsDate() { final Entity eOrig = new Entity(); - eOrig.tAsDate = new Time( new Date().getTime() ); + Calendar calendar = Calendar.getInstance(); + // See javadoc for java.sql.Time: 'The date components should be set to the "zero epoch" value of January 1, 1970 and should not be accessed' + // Other dates can potentially lead to errors in JDBC drivers, in particular MySQL ConnectorJ 8.x. + calendar.set( 1970, Calendar.JANUARY, 1 ); + eOrig.tAsDate = new Time( calendar.getTimeInMillis() ); Session s = openSession(); s.getTransaction().begin(); diff --git a/hibernate-spatial/databases/mysql56/matrix.gradle b/hibernate-spatial/databases/mysql56/matrix.gradle index 68f6ea4f81..361a524b53 100644 --- a/hibernate-spatial/databases/mysql56/matrix.gradle +++ b/hibernate-spatial/databases/mysql56/matrix.gradle @@ -4,4 +4,4 @@ * License: GNU Lesser General Public License (LGPL), version 2.1 or later. * See the lgpl.txt file in the root directory or . */ -jdbcDependency "mysql:mysql-connector-java:5.1.15" +jdbcDependency "mysql:mysql-connector-java:8.0.17" diff --git a/hibernate-spatial/databases/mysql8/matrix.gradle b/hibernate-spatial/databases/mysql8/matrix.gradle index 8ddca02827..361a524b53 100644 --- a/hibernate-spatial/databases/mysql8/matrix.gradle +++ b/hibernate-spatial/databases/mysql8/matrix.gradle @@ -4,4 +4,4 @@ * License: GNU Lesser General Public License (LGPL), version 2.1 or later. * See the lgpl.txt file in the root directory or . */ -jdbcDependency "mysql:mysql-connector-java:8.0.12" +jdbcDependency "mysql:mysql-connector-java:8.0.17"