我对hibernate很新,所以我通过观看视频教程来练习。我关注的链接是,
https://www.youtube.com/watch?v=FFMOZY4z6bE&list=PL4AFF701184976B25&index=5
这是eclipse中简单的java项目。这里我使用mysql数据库。这是我的Hibernate.cfg.xml文件,
com.mysql.jdbc.Driver JDBC:MySQL的://本地主机:3306 / hibernatedb 根 根
<!-- 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"/>
我遇到了这种错误,
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$1.run(Unknown Source)
at java.net.URLClassLoader$1.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)
任何人都可以帮助我。
答案 0 :(得分:3)
如果您使用的是属性文件,请确保该行末尾没有空格。
hibernate.dialect=org.hibernate.dialect.MySQLDialect
答案 1 :(得分:2)
问题的答案就在于此。您在jar文件中找到了MySQLDialect
,但您的配置文件尝试使用MYSQLDialect.Java is case-sensitive
。
尝试更改为
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>