【問題解決】org.hibernate.HibernateException: hibernate.cfg.xml not found
阿新 • • 發佈:2018-12-09
問題描述:
在做最簡單的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>