config文件中不能用绝对路径,要用类路径:com/test/hibernate/Customer.hbm.xml

解决方案 »

  1.   

    我按着你的方法做了,还是有错误:net.sf.hibernate.MappingException: Error reading resource: com/test/hibernate/Customer.hbm.xml at net.sf.hibernate.cfg.Configuration.addResource(Configuration.java:294) at net.sf.hibernate.cfg.Configuration.doConfigure(Configuration.java:944) at net.sf.hibernate.cfg.Configuration.doConfigure(Configuration.java:896) at net.sf.hibernate.cfg.Configuration.configure(Configuration.java:866) at com.test.hibernate.Test.main(Test.java:10)Caused by: net.sf.hibernate.MappingException: persistent class [Customer] not found at net.sf.hibernate.cfg.Binder.bindClass(Binder.java:81) at net.sf.hibernate.cfg.Binder.bindRootClass(Binder.java:207) at net.sf.hibernate.cfg.Binder.bindRoot(Binder.java:1167) at net.sf.hibernate.cfg.Configuration.add(Configuration.java:245) at net.sf.hibernate.cfg.Configuration.addInputStream(Configuration.java:268) at net.sf.hibernate.cfg.Configuration.addResource(Configuration.java:291) ... 4 moreCaused by: java.lang.ClassNotFoundException: Customer at java.net.URLClassLoader$1.run(URLClassLoader.java:198) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:186) at java.lang.ClassLoader.loadClass(ClassLoader.java:299) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:265) at java.lang.ClassLoader.loadClass(ClassLoader.java:255) at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:315) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:140) at net.sf.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:75) at net.sf.hibernate.cfg.Binder.bindClass(Binder.java:78) ... 9 more麻烦你在看一下吧!
      

  2.   

    Caused by: java.lang.ClassNotFoundException: Customer
    Customer.CLASS 没有找到你确定你的Customer.CLASS 文件和Customer.hbm.xml文件 放在com/test/hibernate/文件夹下吗?
      

  3.   

    <class name="Customer" table="CUSTOMER">
    如果这个类在包里的话.要加上包的路径.
      

  4.   

    我的问题OK了,主要有两个原因,一:<class name="Customer" table="CUSTOMER">我应该加上包的路径;二:config文件中不能用绝对路径,要用类路径。
    谢谢大家认真看了我的程序,真的很感谢啊!祝你们身体健康!!