EN:Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set
CN:訪問dialectresolutioninfo不能爲空時,方言沒有設置。
情況一:未在【Hibernat.cfg.xml 】中配置方言
mysql數據庫正常配置如下:
<?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="javax.persistence.validation.mode">none</property>
<!-- dialect 數據庫方言 -->
<property name="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>
<!-- 驅動 -->
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<!-- 數據庫URL -->
<property name="hibernate.connection.url">jdbc:mysql://localhost:3337/hibernateTest</property>
<!-- 數據庫登陸用戶名和密碼 -->
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password"></property>
<!-- 顯示執行SQL語句 -->
<property name="hibernate.show_sql">true</property>
<!-- 格式執行SQL語句 -->
<property name="format.sql">true</property>
<!-- 數據庫自動創建表
create—drop 在程序啓動時創建數據庫表,程序退出時刪除之前創建的表(設計階段使用)
create 在程序啓動的時候先刪除上一次創建的表,然後再創建表結構(設計階段使用)
update 在程序啓動的時候,如果沒有表就創建表,有就檢查更新表(推薦使用)
validate 在程序啓動的時候檢查表結構,不會創建
-->
<property name="hibernate.hbm2ddl.auto">update</property>
<mapping resource="org/enva/pojo/Person.hbm.xml"/>
</session-factory>
</hibernate-configuration>
情況二:Configuration創建錯誤;
簡單的創建,調用例子如下:
import java.util.Date;
import org.enva.pojo.Person;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
public class HibernateTest01 {
public static void main(String[] args) {
Configuration config=new Configuration().configure();
SessionFactory factory=config.buildSessionFactory();
Session session =factory.openSession();
Transaction ts=session.beginTransaction();
Person person=new Person();
person.setName("Tom");
person.setPassword(111111);
person.setBirthday(new Date());
session.save(person);
ts.commit();
session.close();
}
}