Java 如何解决“找不到方言类:org.hibernate.dialect.MYSQLDialect”异常?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25481330/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 00:28:26  来源:igfitidea点击:

How to resolve "Dialect class not found: org.hibernate.dialect.MYSQLDialect" Exception?

javamysqlhibernate

提问by Raghu

I am very new to hibernate so I am practicing by seeing video tutorial. The link I am following is,

我对休眠很陌生,所以我正在通过观看视频教程来练习。我正在关注的链接是,

https://www.youtube.com/watch?v=FFMOZY4z6bE&list=PL4AFF701184976B25&index=5

https://www.youtube.com/watch?v=FFMOZY4z6bE&list=PL4AFF701184976B25&index=5

It is simple java project in eclipse. Here I use mysql Data base. Here is my Hibernate.cfg.xml file,

它是eclipse中的简单java项目。这里我使用mysql数据库。这是我的 Hibernate.cfg.xml 文件,

com.mysql.jdbc.Driver jdbc:mysql://localhost:3306/hibernatedb root root

com.mysql.jdbc.Driver jdbc:mysql://localhost:3306/hibernatedb root root

    <!-- JDBC connection pool (use the built-in) -->
    <property name="connection.pool_size">1</property>

    <!-- SQL dialect -->
    <property name="dialect">org.hibernate.dialect.MYSQLDialect</property>

    <!-- Disable the second-level cache  -->
    <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>

    <!-- Echo all executed SQL to stdout -->
    <property name="show_sql">true</property>

    <!-- Drop and re-create the database schema on startup -->
    <property name="hbm2ddl.auto">create</property>

    <!-- Names the annotated entity class -->
    <mapping class="com.***.dto.UserDetails"/>

I am getting this kind of error ,

我收到这种错误,

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Exception in thread "main" org.hibernate.HibernateException: Dialect class not found:   org.hibernate.dialect.MYSQLDialect
at org.hibernate.dialect.resolver.DialectFactory.constructDialect(DialectFactory.java:159)
at org.hibernate.dialect.resolver.DialectFactory.buildDialect(DialectFactory.java:99)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:117)
at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2863)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2859)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1870)
at com.aurodisplay.hibernate.HibernateTest.main(HibernateTest.java:17)
Caused by: java.lang.ClassNotFoundException: org.hibernate.dialect.MYSQLDialect
at java.net.URLClassLoader.run(Unknown Source)
at java.net.URLClassLoader.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:192)
at org.hibernate.dialect.resolver.DialectFactory.constructDialect(DialectFactory.java:156)

Can any one help me in this.

任何人都可以帮助我。

采纳答案by Ankur Singhal

The answer is in the question. You've found MySQLDialectin your jar files, but your configuration file tries to use MYSQLDialect. Java is case-sensitive.

答案就在问题中。您已MySQLDialect在 jar 文件中找到,但您的配置文件尝试使用MYSQLDialect. Java 区分大小写。

Try changing to below

尝试更改为下面

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

回答by Hemant Nagpal

If you are using a property file, then make sure there is no space at the end of the line.

如果您使用的是属性文件,请确保行尾没有空格。

hibernate.dialect=org.hibernate.dialect.MySQLDialect