-
Notifications
You must be signed in to change notification settings - Fork 38.5k
Consider updating the default Hibernate dialect for MySQL databases #22326
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
According to what @jhoeller said in #19820 (comment) I propose to update the default dialect to |
I'm afraid we can't enforce a newer dialect variant at this point since As for |
I don't expect this to be changed in 5.1.x, but something like this could go into 5.2: try {
return Class.forName("org.hibernate.dialect.MySQL8Dialect");
catch (ClassNotFoundException e) {
return MySQL5Dialect.class;
} It's perfectly fine for us to just put |
The problem there is the upgrade experience: just by updating Hibernate ORM e.g. from 5.2 to 5.3, you'll get a different MySQL dialect against the InnoDB storage engine, against the very same Spring Framework version and the same default settings. Such an effect would be easier to swallow if we could require Hibernate ORM 5.3+ to begin with... so that the experience would be consistent against the same framework version at least, i.e. for all supported Hibernate versions against a particular Spring version. That said, I wonder whether explicitly specifying a database dialect is a good idea in general. Hibernate's default dialect resolution usually gets it right, including version-specific detection. Simply not specifying a database type to begin with would be a sane default strategy for modern-day Hibernate setups. |
@snicoll, @wilkinsona, any thoughts from the Boot side about this? It seems like a rather unfortunate maintenance headache to have to select version-specific Hibernate dialects for the Hibernate's default runtime resolution is smart enough to select the right dialect version these days, but once a dialect has been configured, all of this is overridden. As far as I can see, we can't easily say "MySQL" and get runtime resolution between the MySQL dialect versions; this only kicks in if we don't specify any dialect at all, even letting it detect MySQL itself. See Hibernate's |
What was the rationale behind this decision. As far as I can see, the If a If the general assumption is that we shouldn't attempt to set a database and/or a database platform we can see how we can deprecate these elements and remove them ultimately but I want to make sure we've considered all side effects before doing so. |
See also spring-projects/spring-boot#15342 |
For the record, I've created an issue in Spring Boot to let Hibernate drives the dialect: spring-projects/spring-boot#16172 |
I wonder why SpringBoot 1.5.x will select innodb as its default storage engine, but SpringBoot 2.x select MyISAM as default, what's the point? |
The issue @snicoll brought up is closed but I found that it does not work as of yet and wrote it in the comment spring-projects/spring-boot#16172 (comment) though it should be there for 2.2, for the time being I have added my workaround in the issue as well |
Not sure whether it is relevant, but recently Hibernate fixed a related issue: https://hibernate.atlassian.net/browse/HHH-13910 |
Please consider updating the default Hibernate dialect for MySQL databases.
org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter#determineDatabaseDialectClass
currently returnsorg.hibernate.dialect.MySQL5Dialect
for MySQL databases, while the following newer versions are available:org.hibernate.dialect.MySQL55Dialect
(MySQL 5.5 was first released in 2010)org.hibernate.dialect.MySQL57Dialect
(MySQL 5.7 was first released in 2014)org.hibernate.dialect.MySQL8Dialect
(MySQL 8.0 was first released in 2018)As you can see, the default dialect selected by Spring Framework 5.1.3 targets a MySQL version which is over 9 years old. Therefore I propose to update the default dialect for MySQL.
Background
We're running a Spring Boot 2.1.2 application on MySQL 8 which leads to SQL errors when using the default dialect selected by Spring. Manually updating the dialect to at least
MySQL55Dialect
resolves these issues.This is the line in question:
spring-framework/spring-orm/src/main/java/org/springframework/orm/jpa/vendor/HibernateJpaVendorAdapter.java
Line 192 in 7a77e83
The text was updated successfully, but these errors were encountered: