---
title: "hibernate.dialect' must be set when no Connection available错误"
author: "加菲学Java"
date: "2010-10-18T14:22:17Z"
tags: []
categories: ["企业架构"]
slug: "hibernate-dialect-must-be-set-when-no-connection-available"
draft: false
lastmod: "2010-10-18T14:30:26Z"
id: 787434
url: "https://yklovejava-163-com.iteye.com/blog/787434"
---

```
org.hibernate.HibernateException: 'hibernate.dialect' must be set when no Connection available 
```

 这个问题是比较奇怪的，让人有点郁闷，检查了配置文件，根本没有错，也就说现在问题不是出在这个地方了。而是出现在了其他的地方。网上找了很多，很失望，没有找到正确的。

 

这个时候得看其他的方面。我出现的问题是

 

```
cfg=new AnnotationConfiguration()；
sf=cfg.buildSessionFactory();
```

 

在这里没有写

 

```
cfg=new AnnotationConfiguration().configure();
```

       缺少的是configure();

 添加这句话之后程序OK.

 

 new Configuration()默认是读取hibernate.properties

 所以使用new Configuration().configure()来读取hibernate.cfg.xml文件