【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 ...
随机推荐
- 一起talk C栗子吧(第一百二十四回:C语言实例--内置宏)
各位看官们,大家好,上一回中咱们说的是显示变量和函数地址的样例,这一回咱们说的样例是:内置宏.闲话休提,言归正转.让我们一起talk C栗子吧! 看官们,我们在编译程序的时候,假设有语法错误,编译器就 ...
- iOS与HTML交互问题
一. 加载后台传过来的HTML标签,文字都能正常显示但是图片显示不了.找问题找了很久没有发现那个地方写错,也问了别人都不知道,后来问了Android才知道,后台传过来的HTML标签,有些是转义过的.移 ...
- [读书笔记]流畅的Python(Fluent Python)
<流畅的Python>这本书是图灵科技翻译出版的一本书,作者Luciano Ramalho. 作者从Python的特性角度出发,以Python的数据模型和特殊方法为主线,主要介绍了pyth ...
- sqlserver主机名变更后的错误与处理办法
sqlserver 服务器更改主机名后,须要做一些操作.不然维护计划 以及订阅公布都会有问题,详细过程例如以下:能够參考 有时改动计算机名后,运行select @@servername仍返回原来的计算 ...
- lucene DocValues——本质是为通过docID查找某field的值
什么是docValues? docValues是一种记录doc字段值的一种形式,在例如在结果排序和统计Facet查询时,需要通过docid取字段值的场景下是非常高效的. 为什么要使用docValues ...
- CodeForces-204E:Little Elephant and Strings (广义后缀自动机求出现次数)
The Little Elephant loves strings very much. He has an array a from n strings, consisting of lowerca ...
- 聊聊Shiro
Shiro是项目中用的比较多Java安全框架,能满足大多数项目的安全认证.授权流程.相比SpringSecurity的复杂重量级,它更简单易用. Shiro中最关键的两个概念是认证和授权,前者解决确认 ...
- 杂项-Java:Thymeleaf
ylbtech-杂项-Java:Thymeleaf Thymeleaf is a modern server-side Java template engine for both web and st ...
- .NET获取汉字首字母
/// <summary> /// 获取汉字首字母(可包含多个汉字) /// </summary> /// <param name="strText" ...
- javascript复制内容到剪切板/网页上的复制按钮的实现
javascript复制内容到剪切板/网页上的复制按钮的实现:DEMO如下 <!doctype html> <html> <head> <meta chars ...