【问题解决】org.hibernate.HibernateException: hibernate.cfg.xml not found

版权声明:本文为BUG先生原创文章,可任意转载,愿请附上本文链接,谢谢。 https://blog.csdn.net/Edogawa_Konan/article/details/82685896

问题描述:

在做最简单的SSH的登陆注册时候出现 org.hibernate.HibernateException: hibernate.cfg.xml not found

去看数据库的时候,果然发现表根本没有建出来。

解决方法:

在项目名-src目录下添加hibernate.cfg.xml这个配置文件,添加后刷新项目,重启tomcat,发现表已经建成功,成功解决。

<!DOCTYPE hibernate-configuration PUBLIC
	"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
	"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
	<hibernate-configuration>
		<session-factory>
			<!-- hibernate的方言,用来确定连接的数据库 -->
			<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
			<!-- 数据库的连接类 -->
			<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
			<!-- 数据库的连接字符串和用户名密码 -->
			<property name="hibernate.connection.url">jdbc:mysql://10.0.26.147:3306/test</property>
			<property name="hibernate.connection.username">root</property>
			<property name="hibernate.connection.password">root</property>
			<!-- 在使用hibernate时会显示相应的SQL -->
			<property name="show_sql">true</property>
			<!-- 会自动完成类到数据表的转换 -->
			<property name="hibernate.hbm2ddl.auto">update</property>
			<!-- 加入实体类的映射文件 -->	
			<mapping resource="com/springmvc/model/student.hbm.xml"/>
		</session-factory>
	</hibernate-configuration>

注意:里面的内容要根据你自身来修改哦! 

附:hibernate配置文件hibernate.cfg.xml的详细解释

 

猜你喜欢

转载自blog.csdn.net/Edogawa_Konan/article/details/82685896
今日推荐