当前位置:编程学习 > JAVA >>

Hibernate问题之'hibernate.dialect' not set

 出现  Connection cannot be null when 'hibernate.dialect' not set,明明就在hibernate.cfg.xml配置了,但是还是提示方言为空,原来,少了一个

hibernate.properties文件,添加之后,又出现一大堆问题。

   之前项目不需properties文件,两者的区别就是旧项目用了:

 

<SPAN style="FONT-SIZE: 18px">SessionFactory sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory();</SPAN> 

SessionFactory sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory();


新项目

 

 


<SPAN style="FONT-SIZE: 18px">Configuration configuration = new Configuration(); 
ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry(); 
SessionFactory sessionFactory = configuration.buildSessionFactory(serviceRegistry);</SPAN> 

Configuration configuration = new Configuration();
ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry();
SessionFactory sessionFactory = configuration.buildSessionFactory(serviceRegistry);
原来,少了,configuration.configure()方法

没有configure()就会去classpath找hibernate.properties文件,有configure就去找hibernate.cfg.xm

就这么简单,囧!

 

 


 

补充:软件开发 , Java ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,