org.hibernate.HibernateException: /hibernate.cfg.xml not found等三个问题

初次配置hibernate在myeclipse上:

出现三个问题,怎么都不好使,比对代码,没有问题,查看路径还是没有问题:

1、org.hibernate.HibernateException: /hibernate.cfg.xml not found

路径问题:

说找不到我的hibernate.cfg.xml,比对之后发现没有问题:

配置好后应该是这样的,然后mapping中要使用当前的文件路径,把之前的都删了。

2、This project is not a MyEclipse Hibernate Project. Assuming Hibernate 3 capablites for the configuration editor.;

显示这个没做改动,最后自然好使,有的人说还可以配置下:

myeclipse-->add hibernate capabilites -->next-->hibernate config file --> existing -->选择现有工程存在的hibernate配置文件--> next --> 不生成factory class --> end

更改后我的还是无效,大家可以试试也许你有效。

3、'hibernate.dialect' must be set when no Connection avalable

无奈下我把例子导入了工程中,然后运行,曝出了错误是这个,这个错误说我没有对其进行语言识别的配置,然后我把下边这句加了进去

<property name="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>结构如图:

然后所有问题都消失了。

 4、在数据库中要提前建立好

<property name="connection.url">
jdbc:mysql://localhost:3306/liuyang_person_hibernate
</property>

名字为liuyang_person_hibernate(我的是这个),这个的数据库,然后写好测试类,运行一下就好使了

5、最终结果

原文地址:https://www.cnblogs.com/liuyangfirst/p/5990446.html