Why does MariaDB dialect detection falls back to driverName?

Hello,

The logic in hibernate-orm/hibernate-core/src/main/java/org/hibernate/dialect/Database.java at main · hibernate/hibernate-orm · GitHub, which is the “else” part in this method, checks whether the driverName starts with “MariaDB”. This logic seems to be covering an edge case where the MariaDB server reports itself as MySQL.

I’m curious about this logic, and I tried to go back through the history, only to find that the original MariaDB detection logic, committed in 2017, directly uses the driver name instead of the database product name.

What was the motivation of using driver name for MariaDB? Is it still a valid case nowadays?

		@Override
		public boolean matchesResolutionInfo(DialectResolutionInfo info) {
			if ( productNameMatches( info.getDatabaseName() ) ) {
				return true;
			}
			else {
				//in case the product name has been set to MySQL
				String driverName = info.getDriverName();
				return driverName != null && driverName.startsWith( "MariaDB" );
			}
		}

I’m asking because the MariaDB driver is fully compatible with MySQL server, so people could use this combination, but get a mismatching dialect used by Hibernate.

MariaDB has some differences from MySQL, as you can see from the different implementations of their dialects. The additional check has been implemented because apparently MariaDB can report MySQL as the product name, and we suppose that users would be using the correct driver from their db vendor. I’m not sure I would recomment using MariaDB’s jdbc driver with a MySQL database.

@mbladel Thank you for the explanation. Actually this is the part that I didn’t find any reference:

because apparently MariaDB can report MySQL as the product name

Is there any example/reference for this? Or was this true with older versions when MariaDB still aims at being a drop-in replacement of MySQL, which is no longer true today?

Regarding the driver, the MariaDB driver documents compatibility with both products, and many people think it offers better performance or better license than the MySQL driver. So it’s a legit use case for this combination.

It’s pretty simple, if you’re using MySQL, use the MySQL JDBC driver. If you’re using MariaDB, use the MariaDB JDBC driver. I don’t think you will receive any support from either community if you encounter a problem but use a driver that isn’t officially supported.
You can of course run an unsupported configuration, but the Hibernate ORM team will not spend time on figuring out the potential issues.