diff --git a/databases.gradle b/databases.gradle index 21b161865f..ea2ed8de50 100644 --- a/databases.gradle +++ b/databases.gradle @@ -38,7 +38,7 @@ ext { 'jdbc.url' : 'jdbc:postgresql:hibernate_orm_test' ], mysql : [ - 'db.dialect' : 'org.hibernate.dialect.MySQL57InnoDBDialect', + 'db.dialect' : 'org.hibernate.dialect.MySQL57Dialect', 'jdbc.driver': 'com.mysql.jdbc.Driver', 'jdbc.user' : 'hibernateormtest', 'jdbc.pass' : 'hibernateormtest', diff --git a/documentation/src/main/asciidoc/userguide/chapters/query/spatial/Spatial.adoc b/documentation/src/main/asciidoc/userguide/chapters/query/spatial/Spatial.adoc index 2d830ac9c5..b3a24dbcd9 100644 --- a/documentation/src/main/asciidoc/userguide/chapters/query/spatial/Spatial.adoc +++ b/documentation/src/main/asciidoc/userguide/chapters/query/spatial/Spatial.adoc @@ -137,12 +137,8 @@ There are several dialects for MySQL: `MySQLSpatialDialect`::: a spatially-extended version of Hibernate `MySQLDialect` -`MySQLSpatialInnoDBDialect`::: - a spatially-extended version of Hibernate `MySQLInnoDBDialect` `MySQLSpatial56Dialect`::: a spatially-extended version of Hibernate `MySQL5DBDialect`. -`MySQLSpatial5InnoDBDialect`::: - the same as `MySQLSpatial56Dialect`, but with support for the InnoDB storage engine. [NOTE] ==== @@ -150,7 +146,7 @@ MySQL versions before 5.6.1 had only limited support for spatial operators. Most operators only took account of the minimum bounding rectangles (MBR) of the geometries, and not the geometries themselves. This changed in version 5.6.1 were MySQL introduced `ST_*` spatial operators. -The dialects `MySQLSpatial56Dialect` and `MySQLSpatial5InnoDBDialect` use these newer, more precise operators. +The dialect `MySQLSpatial56Dialect` uses these newer, more precise operators. These dialects may therefore produce results that differ from that of the other spatial dialects. diff --git a/etc/hibernate.properties.template b/etc/hibernate.properties.template index 2df7e5eee8..51438e21b6 100644 --- a/etc/hibernate.properties.template +++ b/etc/hibernate.properties.template @@ -43,8 +43,6 @@ hibernate.connection.url @DB_URL@ #hibernate.dialect org.hibernate.dialect.MySQLDialect -#hibernate.dialect org.hibernate.dialect.MySQLInnoDBDialect -#hibernate.dialect org.hibernate.dialect.MySQLMyISAMDialect #hibernate.connection.driver_class org.gjt.mm.mysql.Driver #hibernate.connection.driver_class com.mysql.jdbc.Driver #hibernate.connection.url jdbc:mysql:///test diff --git a/hibernate-core/src/main/java/org/hibernate/boot/registry/selector/internal/StrategySelectorBuilder.java b/hibernate-core/src/main/java/org/hibernate/boot/registry/selector/internal/StrategySelectorBuilder.java index 53878363aa..ec9c4671a4 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/registry/selector/internal/StrategySelectorBuilder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/registry/selector/internal/StrategySelectorBuilder.java @@ -44,6 +44,7 @@ import org.hibernate.dialect.InterbaseDialect; import org.hibernate.dialect.JDataStoreDialect; import org.hibernate.dialect.MckoiDialect; import org.hibernate.dialect.MimerSQLDialect; +import org.hibernate.dialect.MySQL57Dialect; import org.hibernate.dialect.MySQL57InnoDBDialect; import org.hibernate.dialect.MySQL5Dialect; import org.hibernate.dialect.MySQL5InnoDBDialect; @@ -212,6 +213,7 @@ public class StrategySelectorBuilder { addDialect( strategySelector, MySQL5Dialect.class ); addDialect( strategySelector, MySQL5InnoDBDialect.class ); addDialect( strategySelector, MySQL57InnoDBDialect.class ); + addDialect( strategySelector, MySQL57Dialect.class ); addDialect( strategySelector, Oracle8iDialect.class ); addDialect( strategySelector, Oracle9iDialect.class ); addDialect( strategySelector, Oracle10gDialect.class ); diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/AvailableSettings.java b/hibernate-core/src/main/java/org/hibernate/cfg/AvailableSettings.java index 9afa4aba74..624c4cad39 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/AvailableSettings.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/AvailableSettings.java @@ -379,6 +379,15 @@ public interface AvailableSettings { */ String DIALECT_RESOLVERS = "hibernate.dialect_resolvers"; + /** + * Defines the default storage engine for the relational databases that support multiple storage engines. + * This property must be set either as an Environment variable or JVM System Property. + * That is because the Dialect is bootstrapped prior to Hibernate property resolution. + * + * @since 5.2.9 + */ + String STORAGE_ENGINE = "hibernate.dialect.storage_engine"; + /** * Used to specify the {@link org.hibernate.tool.schema.spi.SchemaManagementTool} to use for performing * schema management. The default is to use {@link org.hibernate.tool.schema.internal.HibernateSchemaManagementTool} diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/Dialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/Dialect.java index 5c955d4428..9d7999f001 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/Dialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/Dialect.java @@ -256,7 +256,6 @@ public abstract class Dialect implements ConversionContext { return instantiateDialect( Environment.getProperties().getProperty( Environment.DIALECT ) ); } - /** * Get an instance of the dialect specified by the given properties or by * the current System properties. diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/InnoDBStorageEngine.java b/hibernate-core/src/main/java/org/hibernate/dialect/InnoDBStorageEngine.java new file mode 100644 index 0000000000..3480eafd84 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/dialect/InnoDBStorageEngine.java @@ -0,0 +1,31 @@ +package org.hibernate.dialect; + +/** + * Represents the InnoDB storage engine. + * + * @author Vlad Mihalcea + */ +public class InnoDBStorageEngine implements MySQLStorageEngine{ + + public static final MySQLStorageEngine INSTANCE = new InnoDBStorageEngine(); + + @Override + public boolean supportsCascadeDelete() { + return true; + } + + @Override + public String getTableTypeString(String engineKeyword) { + return String.format( " %s=InnoDB", engineKeyword ); + } + + @Override + public boolean hasSelfReferentialForeignKeyBug() { + return true; + } + + @Override + public boolean dropConstraints() { + return true; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/MariaDBDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/MariaDBDialect.java index b577564566..92738fdc09 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/MariaDBDialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/MariaDBDialect.java @@ -9,7 +9,7 @@ package org.hibernate.dialect; /** * @author Vlad Mihalcea */ -public class MariaDBDialect extends MySQL5InnoDBDialect { +public class MariaDBDialect extends MySQL5Dialect { public MariaDBDialect() { super(); } diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/MyISAMStorageEngine.java b/hibernate-core/src/main/java/org/hibernate/dialect/MyISAMStorageEngine.java new file mode 100644 index 0000000000..09f5c04391 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/dialect/MyISAMStorageEngine.java @@ -0,0 +1,31 @@ +package org.hibernate.dialect; + +/** + * Represents the MyISAM storage engine. + * + * @author Vlad Mihalcea + */ +public class MyISAMStorageEngine implements MySQLStorageEngine{ + + public static final MySQLStorageEngine INSTANCE = new MyISAMStorageEngine(); + + @Override + public boolean supportsCascadeDelete() { + return false; + } + + @Override + public String getTableTypeString(String engineKeyword) { + return String.format( " %s=MyISAM", engineKeyword ); + } + + @Override + public boolean hasSelfReferentialForeignKeyBug() { + return false; + } + + @Override + public boolean dropConstraints() { + return false; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/MySQL55Dialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/MySQL55Dialect.java new file mode 100644 index 0000000000..fb4ce0e490 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/dialect/MySQL55Dialect.java @@ -0,0 +1,20 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or . + */ +package org.hibernate.dialect; + +/** + * An SQL dialect for MySQL 5.5.x specific features. + * + * @author Vlad Mihalcea + */ +public class MySQL55Dialect extends MySQL5Dialect { + + @Override + protected MySQLStorageEngine getDefaultMySQLStorageEngine() { + return InnoDBStorageEngine.INSTANCE; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/MySQL57Dialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/MySQL57Dialect.java new file mode 100644 index 0000000000..2adf0514bc --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/dialect/MySQL57Dialect.java @@ -0,0 +1,76 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or . + */ +package org.hibernate.dialect; + +import java.sql.Types; + +import org.hibernate.dialect.function.SQLFunction; +import org.hibernate.dialect.function.StaticPrecisionFspTimestampFunction; + +/** + * @author Gail Badner + */ +public class MySQL57Dialect extends MySQL55Dialect { + public MySQL57Dialect() { + super(); + + // For details about MySQL 5.7 support for fractional seconds + // precision (fsp): http://dev.mysql.com/doc/refman/5.7/en/fractional-seconds.html + // Regarding datetime(fsp), "The fsp value, if given, must be + // in the range 0 to 6. A value of 0 signifies that there is + // no fractional part. If omitted, the default precision is 0. + // (This differs from the standard SQL default of 6, for + // compatibility with previous MySQL versions.)". + + // The following is defined because Hibernate currently expects + // the SQL 1992 default of 6 (which is inconsistent with the MySQL + // default). + registerColumnType( Types.TIMESTAMP, "datetime(6)" ); + + // MySQL 5.7 brings JSON native support with a dedicated datatype. + // For more details about MySql new JSON datatype support, see: + // https://dev.mysql.com/doc/refman/5.7/en/json.html + registerColumnType( Types.JAVA_OBJECT, "json" ); + + // MySQL also supports fractional seconds precision for time values + // (time(fsp)). According to SQL 1992, the default for