Caused by: org.hibernate.HibernateException: Connection cannot be null when 'hibernate.dialect' not set

docs.jboss.org文档示例代码:(http://docs.jboss.org/hibernate/annotations/3.5/reference/en/html_single/

1     static {
2         try {
3             sessionFactory = new AnnotationConfiguration()
4                     .configure().buildSessionFactory();
5         } catch (Throwable ex) {
6             // Log exception!
7             throw new ExceptionInInitializerError(ex);
8         }
9     }

测试时出现Caused by: org.hibernate.HibernateException: Connection cannot be null when ‘hibernate.dialect‘ not set

 

自己依赖的是hibernate-core-4.2.7.Final.jar

改成:

1 Configuration cfg = new Configuration().configure();  
2 ServiceRegistry serviceRegistry= new ServiceRegistryBuilder().applySettings(cfg.getProperties()).buildServiceRegistry();  
3 sessionFactory = cfg.buildSessionFactory(serviceRegistry);  

Hibernate官网上找不到说明。网上找的。

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。