【Hibernate】Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set
今天用hibernate框架写crm项目时遇到报错: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set
说是hibernate的dialect没有设置,但是在hibernate.cfg,xml中我已经配置了。主要内容如下:
hibernate.cfg.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- 必选属性 (5个)-->
<!-- 数据库驱动 -->
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<!-- 数据库url -->
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/hibernate</property>
<!-- 数据库用户名 -->
<property name="hibernate.connection.username">root</property>
<!-- 数据库密码 -->
<property name="hibernate.connection.password"></property>
<!-- 数据库方言 : 不同的数据库中,sql语法略有区别 ,指定方言可以让hibernate框架在生成sql语句时,根据 数据库方言生成。 -->
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property> <!-- 可选属性(3个) -->
<!-- 将hibernate生成的sql语句打印到控制台 -->
<property name="hibernate.show_sql">true</property>
<!-- 将hibernate生成的sql语句格式化 -->
<property name="hibernate.format_sql">true</property> <!--## auto schema export 自动导出表,构建表
#hibernate.hbm2ddl.auto create(每次框架运行完之后都会创建新表,之前的表会被覆盖。)
#hibernate.hbm2ddl.auto create-drop (每次框架运行完之后都会将所有表删除)
#hibernate.hbm2ddl.auto update (如果有表变动,会自动更新有改变的表)
#hibernate.hbm2ddl.auto validate(校验 )不自动生成表-->
<property name="hibernate.hbm2ddl.auto">update</property>
<!-- 引入orm元数据 -->
<mapping resource="com/ysong/domain/Customer.hbm.xml"/>
</session-factory> </hibernate-configuration>
Customer.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"> <!-- package:填写一个包名,需要书写完整类名的属性,可以写简答类名 -->
<hibernate-mapping package="com.ysong.domain">
<!-- class元素:配置实体与表的关系 name:完整类名 table:数据库表名 -->
<class name="Customer" table="Customer">
<!-- id:配置主键列名映射属性 name:填写主键对应属性名 column:表中的主键列名 (不建议填,让hibernate自动指定类型)type(可选):填写列(属性)的类型。hibernate会自动检测实体的属性类型
每个类型有三种填法:java类型(java.long.String)|hibernate类型(String)|数据库类型(varchar) lenth(可选):配置数据库中列的长度,默认值
:数据库类型的最大长度 not-null(可选):配置该属性(列)是否不能为空,默认值:false -->
<id name="cust_id" column="cust_id">
<!-- generator:主键生成策略 -->
<generator class="native"></generator>
</id> <!-- property:除id之外的列名 name:填写属性名 column:表中的除主键以外的列名 (不建议填,让hibernate自动指定类型)type(可选):填写列(属性)的类型。hibernate会自动检测实体的属性类型
每个类型有三种填法:java类型(java.long.String)|hibernate类型(String)|数据库类型(varchar) lenth(可选):配置数据库中列的长度,默认值
:数据库类型的最大长度 not-null(可选):配置该属性(列)是否不能为空,默认值:false -->
<property name="cust_name" column="cust_name"></property>
<property name="cust_source" column="cust_source"></property>
<property name="cust_level" column="cust_level"></property>
<property name="cust_linkman" column="cust_linkman"></property>
<property name="cust_phone" column="cust_phone"></property>
<property name="cust_mobile" column="cust_mobile"></property>
</class> </hibernate-mapping>
HibernateUtils:
package com.ysong.utils; import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration; public class HibernateUtils {
private static SessionFactory sessionFactory;
static {
Configuration configuration = new Configuration();
sessionFactory = configuration.buildSessionFactory();
}
// 获得session=> 获得全新session
public static Session openSession() {
Session session = sessionFactory.openSession();
return session;
} // 获得session=> 获得与线程绑定的session
public static Session getCurrentSession() {
Session session = sessionFactory.getCurrentSession();
return session;
}
}
最后从百度到的一篇文章中找到答案:
原来,这里的new configuration();应该改成new Configuration().configure();
没有configure()就会去classpath找hibernate.properties文件,有configure就去找hibernate.cfg.xml文件。

到此这是今天遇到的问题,记录下来以后不要犯同样的错!
【Hibernate】Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set的更多相关文章
- 【方言】Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set
Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set 几种 方言配置差异 <?xml v ...
- [Hibernate]Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set
使用Hibernate官方文档上的下面代码进行測试时报出这个异常. org.hibernate.HibernateException: Access to DialectResolutionInfo ...
- 【c3p0】目前使用它的开源项目有Hibernate,Spring等
C3P0是一个开源的JDBC连接池,它实现了数据源和JNDI绑定,支持JDBC3规范和JDBC2的标准扩展.目前使用它的开源项目有Hibernate,Spring等. c3p0与dbcp区别 JNDI ...
- C#【数据库】 Access类
using System; using System.Data; using System.Data.OleDb; namespace AccessDb { /**//// <summary&g ...
- 【Druid】access denied for user ''@'ip'
今天在写单元测试时,遇到一个很奇葩的问题,一直在报这样的错误: Caused by: java.sql.SQLException: Access denied for user ''@'183.134 ...
- 【转】于request.getSession(true/false/null)的区别
http://blog.csdn.net/gaolinwu/article/details/7285783 关于request.getSession(true/false/null)的区别 一.需求原 ...
- 【C#】允许泛型方法<T>返回空值Null
在设计一个返回类型为T的泛型方法时,有时希望能返回空Null,然后会报错: 根据提示,将返回值由Null改为default(T)即可. default(T)表示返回当前T类型的默认值,如果T为int则 ...
- 【转载++】fopen返回0(空指针NULL)且GetLastError是0
结论来看,是一个简单又朴素的道理——打开文件句柄用完了得给关上.表现在现象上却是着实让人费解,以至于有人还怀疑起了微软的Winodws系统来了,可笑至极.还是那句话,先把自己的屁股先给擦干净喽再怀疑别 ...
- postgres-xl 安装与部署 【异常处理】ERROR: could not open file (null)/STDIN_***_0 for write, No such file or directory
https://www.jianshu.com/p/82aaf352b772 这篇文章很不错,里面有个bug,可能是版本不对. 当前(2018-04-11)通过git 下载原代码时,在配置 pgxc ...
随机推荐
- 基于github for windows&github的团队协作基本操作
首先,我们要在github上团队协作.先要建立一个team.这个自行百度,在github上操作就是. 点击打开链接 这是我的有道文章(假设看不到图片的话) 今天主要讲的是怎么操作github for ...
- UVa 401 Palindromes(镜像回文字符串)
题意 给一个字符串 判定其是否为回文串和镜像串 回文串非常好推断 镜像串对于每个字符用数组保存它的镜像字符即可了 没有的就是空格 注意若字符串长度为奇数 中间那个字母必须是对称的才是镜 ...
- asp.net项目与开源单点登录项目CAS的结合
这段时间搞的一个asp.net mvc项目,采用了单点登录. 这个单点登录就是CAS,一个开源的JAVA项目.当然,这并不影响ASP.NET项目结合它来进行登录.因为各自分工不同:单点登录(管它是不是 ...
- VMware一些使用心得
这段时间VMware workstation用得较多,装了好几个虚拟机,有win2003,win2008,win7,还分32位,64位.装了这么多,要么是用于安装一些软件,比如oracle12c,因为 ...
- 一些java错误
@Override must override a superclass method 问题解决 如果在使用Eclipse开发Java项目时,在使用 @Override 出现以下错误: The met ...
- kernel: audit: printk limit exceeded
问题: 小长假的第一天早上8:18一个数据,被定时任务中的脚本漏处理: 查定时任务的日志,发现调度异常 查var messages-20171231 日志信息,排查问题. http://man7.or ...
- 定时邮件 已经稳定运行10天+ 从局域网linux到外网邮箱
- 设计模式-(6)适配器 (swift版)
用来解决接口适配问题的三种模式:适配器模式,桥接模式,外观模式. 一,概念 适配器模式,将一个类的结构转换成用户希望的另一个接口,使得原本接口不兼容的类能在一起工作.换句话说,适配器模式就是链接两种不 ...
- publish and submit
http://blog.csdn.net/w_jewelry/article/details/8123639 1.Gerrit里点击“publish and submit”提示如下:Your chan ...
- 专用于ASP.Net Web应用程序的日期控件
原文引入:http://blog.csdn.net/nileel/article/details/1566051 专用于ASP.Net Web应用程序的日期控件 分类: ASP.NET/C#2007 ...