vishnu
vishnu

Reputation: 197

How to mention MySQLDialect for Hibernate 5.4.17 and MySQL 8.0?

I'm using Hibernate 5.4.17 in the hibernate.cfg.xml file. I have the dialect property like this:

<property name="dialect">org.hibernate.dialect.MySQLDialect</property>

Is this fine to use or Should I change it to:

 <property name="dialect">org.hibernate.dialect.MySQL8Dialect</property>

Upvotes: 1

Views: 5258

Answers (2)

Aron Foster
Aron Foster

Reputation: 577

For others stumbling upon this answer: This has changed for newer versions of Hibernate. From the Hibernate documentation:

Since Hibernate 6, a single subclass of Dialect represents all releases of a given product-specific SQL dialect. The version of the database is exposed at runtime via the DialectResolutionInfo passed to the constructor, and by the getVersion() property.

Programs using Hibernate should migrate away from the use of versioned dialect classes like, for example, MySQL8Dialect. These classes are now deprecated and will be removed in a future release.

So you should use org.hibernate.dialect.MySQLDialect if you have hibernate 6 or above.

Upvotes: 2

SternK
SternK

Reputation: 13111

The version of your hibernate dialect should be as closer as possible to your database version. But should not be higher than database version. So for your case the org.hibernate.dialect.MySQL8Dialect will be the best choice.

See also this section of the hibernate documentation for further details.

Upvotes: 1

Related Questions