使用hibernate3.3连接mysql问题
hibernate包导入,vo和与数据库映射文件,配置文件写了
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="connection.username">root</property>
<property name="connection.url">
jdbc:mysql://localhost:3306/oa
</property>
<property name="dialect">
org.hibernate.dialect.MySQLDialect
</property>
<property name="myeclipse.connection.profile">mysql</property>
<property name="connection.password">pass</property>
<property name="connection.driver_class">
com.mysql.jdbc.Driver
</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<property name="show_sql">true</property>
<property name="connection.autocommit">true</property>
<mapping resource="com/oa/xml/hibernate/Notice.hbm.xml" />
</session-factory>
</hibernate-configuration>
测试代码如下:
Configuration cfg = new Configuration();
SessionFactory sf = cfg.buildSessionFactory();
Session session = sf.openSession();
出现异常如下:
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/F:/OA%e9%a1%b9%e7%9b%ae/OA/lib/slf4j-nop-1.5.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/F:/OA%e9%a1%b9%e7%9b%ae/OA/lib/slf4j-simple-1.5.8.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
Exception in thread "main" org.hibernate.HibernateException: Hibernate Dialect must be explicitly set
at org.hibernate.dialect.DialectFactory.determineDialect(DialectFactory.java:80)
at org.hibernate.dialect.DialectFactory.buildDialect(DialectFactory.java:62)
at org.hibernate.cfg.SettingsFactory.determineDialect(SettingsFactory.java:460)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:155)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2101)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1325)
at com.oa.test.Test.main(Test.java:11)