在做hibernate 的小例子是出现了'hibernate.dialect' must be set when no Connection available 异常
但是在 hibernate.cfg.xml中存在<property name="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</property>配置
得出问题不是在sql 方言上.
进一步检查得出在读取配置文件时.少写了configure()
如果这样写
SessionFactory conf=new Configuration().buildSessionFactory();
在程序中不会有错误(即出现红色差号),但是上面没有configure()便不会读取hibernate.cfg.xml 配置文件
configure()默认的读取名为hibernate.cfg.xml的配置
正确写法
SessionFactory conf=new Configuration().configure().buildSessionFactory();
异常解决