Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set——【hibernate 日常错误】

来源:互联网 发布:求生之路2游侠网络联机 编辑:程序博客网 时间:2024/06/12 20:00

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();
        
    }
}

0 0
原创粉丝点击