Hibernate Dialect must be explicitly set的异常
异常是这样org.hibernate.HibernateException: Hibernate Dialect must be explicitly set
发生这样异常的原因有:
1).dialect配置有误或忘记配置dialect
MySQL数据库的dialect配置:
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
2).忘记写configure().
正确写法:
publicvoidsave(Loginlogin){
Configurationconfig=newConfiguration();
SessionFactorysf=config.configure().buildSessionFactory();Sessions=sf.openSession();
Transactiont=s.beginTransaction();
s.save(login);
t.commit();
s.close();
}错误写法:
publicvoidsave(Loginlogin){
Configurationconfig=newConfiguration();
SessionFactorysf=config.buildSessionFactory();Sessions=sf.openSession();
Transactiont=s.beginTransaction();
s.save(login);
t.commit();
s.close();
}3).数据库表的字段名中有空格或者是关键字,将包含该字段的sql语句放到MS Server的查询分析器,你会发现该字段变
成了蓝色如:record date
直接将Hibernate打印出来的sql语句发送到数据库里执行一下,也是报错,
insert into dataanalysis(url, describe, userid, createusername, record date, id) values ('aa', 'bb', 'cc', 'dd', '2010-01-01', 'abcd123');
改为:
insert into dataanalysis(url, describe, userid, username, record date, id) values ('aa', 'bb', 'cc', 'dd', '2010-01-01', 'abcd123');
再运行,OK了