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官网上没找到说明。网上找的。

posted @ 2015-03-22 22:56  xiluhua  阅读(872)  评论(0编辑  收藏  举报