一个hibernate的测试却出现了这样的错误
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" org.hibernate.MappingNotFoundException: resource: po.Student.hbm.xml not found
at org.hibernate.cfg.Configuration.addResource(Configuration.java:563)
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1587)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1555)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1534)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1508)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1428)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1414)
at test.Query.main(Query.java:11)
现在错误指向了Configuration conf=new Configuration().configure();这一行
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;import po.Student;public class Query {
public static void main(String[] args){
Configuration conf=new Configuration().configure();
SessionFactory sf=conf.buildSessionFactory();
Session session=sf.openSession();
Student stu=(Student)session.get(Student.class, "112345678");
String name= stu.getName();
String id= stu.getId();
String sex= stu.getSex();
String age=stu.getAge();
String birthday= stu.getBirthday();
String major= stu.getName();
System.out.println("姓名"+name);
System.out.println("学号"+id);
System.out.println("性别"+sex);
System.out.println("年龄"+age);
System.out.println("出生年月"+birthday);
System.out.println("专业"+major);

}}

解决方案 »

  1.   

    错误原因说 po.Student.hbm.xml找不到,你可能是hibernate.cfg.xml里面的mapping那里写错了,或者你没有配这个实体的xml属性文件
      

  2.   

    楼上正解。。
    找不到po.Student.hbm.xml
    查一下是否路径有问题 或者 不存在此xml文件
      

  3.   

    Exception in thread "main" org.hibernate.MappingNotFoundException: resource: po.Student.hbm.xml not found
    po.Student.hbm.xml这个 hbm文件没有找到 ,先确认你的 po包中存在po.Student.hbm.xml 在 hibernate.cfg.xml 中配置正确的路径<mapping resource="po/Student.hbm.xml"/> <!--应该用po/Student.hbm.xml而不是 po.Student.hbm.xml -->