【发布时间】:2017-11-02 07:20:39
【问题描述】:
我正在尝试使用 hibernate 将一个正常的插入代码连接到 mysql 数据库并为此出错,我在下面写了异常详细信息。
log4j:WARN No appenders could be found for logger (org.jboss.logging).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" org.hibernate.internal.util.config.ConfigurationException: Could not locate cfg.xml resource [/home/controller/Documents/sts_work/webtracker/src/main/java/hibernate.cfg.xml]
at org.hibernate.boot.cfgxml.internal.ConfigLoader.loadConfigXmlResource(ConfigLoader.java:53)
at org.hibernate.boot.registry.StandardServiceRegistryBuilder.configure(StandardServiceRegistryBuilder.java:163)
at org.hibernate.cfg.Configuration.configure(Configuration.java:258)
at testHBConnection.main(testHBConnection.java:12)
我用于测试的 java 文件是
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import com.ar.entity.Student;
public class testHBConnection {
public static void main(String[] args) {
// TODO Auto-generated method stub
SessionFactory sf=new Configuration().configure("/home/controller/Documents/sts_work/webtracker/src/main/java/hibernate.cfg.xml")
.addAnnotatedClass(Student.class)
.buildSessionFactory();
Session ses=sf.getCurrentSession();
try {
Student stu= new Student("","name");
ses.beginTransaction();
ses.save(stu);
ses.getTransaction().commit();
}
catch(Exception e) {
System.out.println("Exception "+e);
}
finally{
}
}
}
我在下面链接了我的项目结构
其中 Student 是关联到数据库表的 pojo 文件 我该如何解决这个问题?
【问题讨论】:
-
您确定 hibernate.cfg.xml 存在于绝对位置吗?
标签: java hibernate jakarta-ee