[英]Hibernate 5 : can't find config file
我今天發現了Hibernate,並且在嘗試使一個最小的程序找到我的“ hibernate.cfg.xml”配置文件時遇到了麻煩。
這是我已經嘗試過的:
我的主要:
package testHibernate;
import org.hibernate.cfg.Configuration;
public class Main
{
public static void main(String[] args)
{
Configuration configuration = new Configuration().configure();
}
}
在此主文件的同一級別:
hibernate.cfg.xml
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration SYSTEM
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<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://localhost:3306/pianissimo</property>
<property name="hibernate.connection.username">admin</property>
<property name="hibernate.connection.password">nx5fDdVdEGVDS6Tq</property>
</session-factory>
</hibernate-configuration>
任何幫助將不勝感激:)真誠的,Alann
您不應將hibernate.cfg.xml
與Main
類放在同一級別。 您應該將其放在源文件夾根目錄中與testHibernate
包相同的級別。 或者您需要像這樣指定hibernate.cfg.xml
的路徑
Configuration configuration =
new Configuration().configure("/testHibernate/hibernate.cfg.xml");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.