【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 ...
随机推荐
- Linux下kill命令的学习,(主要根据man手册进行的翻译)
名字 kill -终止一个进程 格式 kill [-s signal | -p] [--] pid .. ...
- ZrcListView
https://github.com/zarics/ZrcListView
- 【CSS3动画实战】Mailman Icon
周末闲来无事,就想着做点东西练练手.又苦于自己 PS 水平太差,设计不出什么好看的东西. 干脆就在 Dribbble 上逛一逛,看看有什么看起来比较屌的,实际上却很简单的东西. 一共做了 3 个,均已 ...
- Lnixu Bash
一.简单命令 1.创建文件(vi) vi hellowold.txt2.创建目录(mkdir) mkdir linux_bash3.删除文件(rm) rm helloworld.txt4.复制文件(c ...
- js实现replaceAll功能
js中没有原生的replaceAll 方法. function replaceAll(str , replaceKey , replaceVal){ var reg = new RegExp(repl ...
- Statement 与 PreparedStatement 区别
Statement由方法createStatement()创建,该对象用于发送简单的SQL语句 PreparedStatement由方法prepareStatement()创建,该对象用于发送带有一个 ...
- mac系统下mysql5.7.13数据库编码查看和设置
1.查看编码命令: mysql> show variables like '%character%'; +--------------------------+----------------- ...
- 二:网络--GET请求和POST请求
一.GET请求和POST请求简单说明 GET - 从指定的服务器中获取数据 POST - 提交数据给指定的服务器处理 GET方法: 使用GET方法时,查询字符串(键值对)被附加在URL地址后面一起发送 ...
- mongoDB 安全权限访问控制
MongoDB3.0权限 https://blog.csdn.net/leonzhouwei/article/details/46564141 转自:http://ibruce.info/2015/0 ...
- Cortex-M3 / M4 Hard Fault Handler (转载)
转自大伟的,感谢大伟的帮助调试:http://www.cnblogs.com/shangdawei/archive/2013/04/30/3052491.html http://blog.frankv ...