使用資料庫為MYSQL
在連接資料庫的時候有錯誤
錯誤訊息:
hibernate reading schema error :hibernate.dialect must be set when no Connection available
這是我的cfg.xml :
<?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="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.password">1111</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/contactdb?zeroDateTimeBehavior=convertToNull</property>
<property name="hibernate.connection.username">Root</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<!-- <property name="dialect">org.hibernate.dialect.MySQLDialect</property> -->
<mapping resource="com/sh/value/Contact.hbm.xml"/>
</session-factory>
</hibernate-configuration>
這是我的hbm.xml :
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.sh.value">
<class name="com.sh.value.Contact" table="contactdb" catalog="contact">
<id name="id" column="id">
<generator class="increment"></generator>
</id>
<property name="name" column="name" />
<property name="email" column="email" />
<property name="address" column="address" />
<property name="telephone" column="telephone" />
</class>
</hibernate-mapping>
在網路上爬了很多國外的文章,但都沒有解決,請各位前輩指點一下!